【发布时间】:2022-07-15 21:44:52
【问题描述】:
我想输入一个整数,并且我希望 python 通过转换返回我的语句。我不知道如何解决这个问题。代码如下
subjectConversions = {
"1": "Computer science",
"2": "Geography",
"3": "History",
"4": "French",
"5": "Drama",
"6": "Music",
"7": "Art",
"8": "Design & Technology",
"9": "Physical Education",
"10": "Cooking",
"11": "Business studies",
}
if year != "y":
print("Sorry! Year 9 only!")
quit()
elif year == "y":
print("Welcome!")
print("Take a look at the list below for GCSE subjects. Once that is done, select four different options at each prompt.\nComputer Science [1], Geography [2], History [3], French [4], Drama [5], Music [6], Art [7], Desingn & Technology [8], Physical Education [9], Cooking [10], Business studies [11]\n")
Op1 = int(input("Option one: "))
print("You have selected" + (subjectConversions[Op1]) + ", is that correct? [y/n]")```
【问题讨论】:
-
你的字典的键应该是像
1这样的整数,而不是像"1"这样的字符串,因为你将用户输入Op1转换为int
标签: python