Python Forum
Multiple Question Results code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Question Results code
#2
I am not entirely sure what do you want, but you might consider to use a dictionary to store your questions/point values - that way you would not need to repeat basically same code ten times.

questions = {"1": "Text of question 1", "2": "Text of question 2", "3": "Text of question 3"}

choice = input()

time.sleep(0.7)
print(questions.get(choice, "Choice must be 1..3"))
you can use questions[choice] to get the value from a dictionary, but with .get() you wont get error when your choice is not in the dictionary.
Reply


Messages In This Thread
Multiple Question Results code - by flynnmackie - Mar-13-2017, 04:38 PM
RE: Multiple Question Results code - by zivoni - Mar-13-2017, 05:41 PM
RE: Multiple Question Results code - by snippsat - Mar-13-2017, 06:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Code works but doesn't give the right results colin_dent 2 807 Jun-22-2023, 06:04 PM
Last Post: jefsummers
  python multiple try except block in my code -- can we shorten code mg24 10 6,558 Nov-10-2022, 12:48 PM
Last Post: DeaD_EyE
  Compiling Python 3.8.5 source code results in build error Deepan 0 2,243 Sep-14-2020, 04:11 AM
Last Post: Deepan
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,312 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  question: finding multiple strings within string djf123 4 3,071 May-16-2020, 01:00 PM
Last Post: snippsat
  Different results of code with local account and technical account dreyz64 7 3,789 Mar-05-2020, 11:50 AM
Last Post: dreyz64
  How to append one function1 results to function2 results SriRajesh 5 3,297 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  multiple problems with code SrijaRamarthy 2 1,942 Nov-06-2019, 06:24 AM
Last Post: SrijaRamarthy
  printing multiple results together kumaaaa 3 1,872 Sep-29-2019, 02:19 AM
Last Post: kumaaaa
  How to execute a string with multiple sqlite statements and print results? shanepy 0 2,309 Nov-20-2018, 10:19 PM
Last Post: shanepy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020