文章目录
- 题目1
- 代码
- 实验结果
- 题目2
- 代码
- 实验结果
- 题目总结
题目1
注册课程小游戏程序
研究下面的例子,并编写一个与这些例子完全相同的程序。使用for loop和break来解决问题。提示用户输入课程数量,是否选择,并且课程代码,最后还需显示已经完成的课程注册数量或者未完成的注册数量,如下如所示:
代码
num_subjects = int(input("How many subjects would you choose for this session: "))
enrolled_subjects = 0while enrolled_subjects < num_subjects:continue_enrollment = input("Would you like to continue subject enrolment? (Y/N): ")if continue_enrollment.upper() == "Y":subject = input("Which subject would you like: ")print("You have successfully enrolled in", subject + ".")enrolled_subjects += 1else:breakremaining_subjects = num_subjects - enrolled_subjectsif remaining_subjects == 0:print("You have finished the enrollment of all", num_subjects, "subjects.")
else:if remaining_subjects == 1 :print("You have not completely finished the enrollment. There is", remaining_subjects, "subject to be enrolled.")else:print("You have not completely finished the enrollment. There are", remaining_subjects, "subjects to be enrolled.")
实验结果
</