python 如果在最后一行消息中以打印语句形式回答y/n,如何获取新学员

9vw9lbht  于 2023-02-18  发布在  Python
关注(0)|答案(2)|浏览(76)
sStudent = input("Are you a new student? y/n")
if "y" == sStudent:
    print**("Welcome to Henry Ford College!")**
elif "n" == sStudent:
    print**("Welcome back to HFC!")**

iCreditRate = input("Enter credit hour rate")
iNumCred = int(input("Enter number of credits this semester"))
sLabFee = input("Do you have any Lab fees?")`

欢迎回来或欢迎消息需要在哪里

尝试让新学生的y/n打印消息仅显示为程序最后一行消息。

j9per5c4

j9per5c41#

您可以尝试使用一个布尔变量来存储值,然后在程序结束时,您可以再次使用if语句,并根据布尔变量的值打印相应的消息。

rdlzhqv9

rdlzhqv92#

放置

if "y" == sStudent:
    print("Welcome to Henry Ford College!")
elif "n" == sStudent:
    print("Welcome back to HFC!")

在程序结束时

相关问题