写一个职工录入信息的代码
时间: 2024-05-03 14:20:37 浏览: 17
好的,下面是一个简单的职工信息录入代码示例:
```python
employee_list = [] # 存储职工信息的列表
while True:
# 逐个输入职工信息
name = input("请输入职工姓名:")
age = input("请输入职工年龄:")
gender = input("请输入职工性别:")
department = input("请输入职工所在部门:")
# 将职工信息存入字典中
employee = {'name': name, 'age': age, 'gender': gender, 'department': department}
# 将职工信息添加到列表中
employee_list.append(employee)
# 继续输入下一个职工信息或结束录入
flag = input("是否继续录入?(输入y继续,其他键结束)")
if flag.lower() != 'y':
break
# 输出职工列表
print("职工信息列表:")
for employee in employee_list:
print("姓名:{name},年龄:{age},性别:{gender},部门:{department}".format(**employee))
```
注意:该示例代码并未考虑数据合法性和异常处理问题,实际生产环境中需加以考虑。
相关问题
请用java写一个录入员工信息界面
好的,以下是一个简单的Java录入员工信息界面代码:
```java
import java.util.Scanner;
public class EmployeeInfo {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("输入员工信息:");
System.out.print("姓名:");
String name = keyboard.nextLine();
System.out.print("年龄:");
int age = keyboard.nextInt();
keyboard.nextLine();
System.out.print("性别:");
String gender = keyboard.nextLine();
System.out.print("工号:");
int id = keyboard.nextInt();
System.out.print("薪水:");
double salary = keyboard.nextDouble();
System.out.println("----------------------");
System.out.println("员工信息:");
System.out.println("姓名:" + name);
System.out.println("年龄:" + age);
System.out.println("性别:" + gender);
System.out.println("工号:" + id);
System.out.println("薪水:" + salary);
}
}
```
运行程序后,将提示您输入员工信息,依次录入后将输出员工信息。
希望能对您有所帮助。
写一个员工管理系统c语言代码
以下是一个简单的员工管理系统的C语言代码,包含了基本的员工信息录入、查询和修改功能:
```c
#include <stdio.h>
#include <string.h>
#define MAX_NUM_EMPLOYEES 100
struct Employee {
char name[50];
int id;
float salary;
};
int num_employees = 0;
struct Employee employees[MAX_NUM_EMPLOYEES];
int add_employee() {
if (num_employees >= MAX_NUM_EMPLOYEES) {
printf("Error: Maximum number of employees exceeded.\n");
return 0;
}
struct Employee new_employee;
printf("Enter employee name: ");
scanf("%s", new_employee.name);
printf("Enter employee ID: ");
scanf("%d", &new_employee.id);
printf("Enter employee salary: ");
scanf("%f", &new_employee.salary);
employees[num_employees++] = new_employee;
printf("Employee added successfully.\n");
return 1;
}
int find_employee(int id) {
for (int i = 0; i < num_employees; i++) {
if (employees[i].id == id) {
return i;
}
}
return -1;
}
int search_employee() {
int id;
printf("Enter employee ID: ");
scanf("%d", &id);
int index = find_employee(id);
if (index == -1) {
printf("Error: Employee not found.\n");
return 0;
}
printf("Employee name: %s\n", employees[index].name);
printf("Employee ID: %d\n", employees[index].id);
printf("Employee salary: %.2f\n", employees[index].salary);
return 1;
}
int update_employee() {
int id;
printf("Enter employee ID: ");
scanf("%d", &id);
int index = find_employee(id);
if (index == -1) {
printf("Error: Employee not found.\n");
return 0;
}
struct Employee updated_employee;
printf("Enter new employee name: ");
scanf("%s", updated_employee.name);
printf("Enter new employee ID: ");
scanf("%d", &updated_employee.id);
printf("Enter new employee salary: ");
scanf("%f", &updated_employee.salary);
employees[index] = updated_employee;
printf("Employee updated successfully.\n");
return 1;
}
int main() {
int choice;
do {
printf("\nEmployee Management System\n");
printf("--------------------------\n");
printf("1. Add Employee\n");
printf("2. Search Employee\n");
printf("3. Update Employee\n");
printf("4. Exit\n");
printf("--------------------------\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
add_employee();
break;
case 2:
search_employee();
break;
case 3:
update_employee();
break;
case 4:
printf("Goodbye!\n");
break;
default:
printf("Invalid choice. Please try again.\n");
break;
}
} while (choice != 4);
return 0;
}
```
该代码定义了一个`Employee`结构体,其中包含了员工的姓名、ID和薪水信息。该程序支持添加员工、查询员工和更新员工信息的功能,并使用了一个简单的菜单来帮助用户进行操作。