python测验与主题选项

时间:2018-03-13 11:44:15

标签: python

 print("plese choose a topic of your liking")
History = ('History')
Music = ('Music')
Computer_science = ('Computer science')
print (History, Music, Computer_science)


History = print("when did the Reichstag fires begin?")
one = ("1) 1937")
two = ("2) 1933")
three = ("3) 1935")
print (one, two, three)
guess = int(input())
if guess == 2: #this makes it so any option appart from 2 is outputed as 'wrong'
    print ("well done")
else:
    print("wrong") 

我已经创建了我的python测验的第一部分,我花了一段时间才弄明白,我还创建了一个包含3个不同主题的列表,你们中的任何人都知道如何为我内部的每个元素指定一个按钮主题清单?如果这没有任何意义,请告诉我(我是这个网站的新手)

1 个答案:

答案 0 :(得分:0)

要获得此类行为,您可以在其他所有内容之前进行输入,以确定您根据用户输入选择的主题。所以真的很简单:

subject = int(input("Please choose what subject you would like 
(number):\n[1]History\n[2]Maths\n[3]Geography\n"))

if subject == 1:
    print("You have chosen History")
elif subject == 2:
    print("You have chosen Maths")
elif subject == 3:
    print("You have chosen Geography")
else:
    print("that is not an available option")

这可能是最简单的菜单...如果您输入1并按Enter键,您将获得历史记录,依此类推。我不知道你的程序是如何工作的,但做的是什么。

这可能是更好的方式,这就是我记得在当天做的事情。非常简单的东西