I'm currently developing a very simple phone troubleshooting system with python which should include 10 possible outcomes. I have created the flowchart below to help me with the process but I'm still struggling with asking many questions which lead to another question etc.
Flowchart: //drive.google.com/file/d/0B9kYvbwMV4pzczJoUUZLcW1mWmc/view?usp=sharing
Current python code:
print ['screen question1 here']
screen1 = raw_input['user answer']
if screen1 == 'yes':
print['screen question2 here']
screen2 = raw_input['user answer']
else:
print['battery question1 here']
battery1 = raw_input['user answer']
if battery1 == 'yes':
print['battery question2 here']
battery2 = raw_input['user answer']
else:
print['wifi question1 here']
wifi1 = raw_input['user answer']
if screen2 == 'yes':
print['screen question3 here']
screen3 = raw_input['user answer']
else:
print['camera question1 here']
camera1 = raw_input['user answer']
Can someone lead me in the right direction, thanks.
asked May 2, 2017 at 19:01
2
It seems you just are not implementing the proper control flow in your file. If you want another question to occur depending upon a previous one, then you just encapsulate that question in that conditional.
print ['screen question1 here']
screen1 = raw_input['user answer']
if screen1 == 'yes':
print['screen question2 here']
screen2 = raw_input['user answer']
if screen2 == 'yes':
print['screen question3 here']
screen3 = raw_input['user answer']
else:
print['camera question1 here']
camera1 = raw_input['user answer']
else:
print['battery question1 here']
battery1 = raw_input['user answer']
if battery1 == 'yes':
print['battery question2 here']
battery2 = raw_input['user answer']
else:
print['wifi question1 here']
wifi1 = raw_input['user answer']
Looking quickly at the diagram you shared, this seems to be what you are looking for. The documentation for More Control Flow Tools provides nice documentation on this subject.
answered May 2, 2017 at 19:20
Using while true with if statement you can make a multiple-choice question in Python. stop the loop if the user enters “Q”. Simple example code making a very simple multiple-choice story in Python, repeat if neither of the options is selected. Output:while True:
d1a = input["Do you want to: \n A] House. B] Stable. [A/B]? : "]
if d1a == "A":
print["You approach the cottage."]
elif d1a == "B":
print["You approach the stables."]
elif d1a == "Q":
print["Done!"]
break
Do comment if you have any doubts or suggestions on this Python program code.
Note: IDE: PyCharm 2021.3.3 [Community Edition]
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.
This is a script to make you do fast multiple choice questions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | from random import shuffle alt1="""red, rosso yellow, giallo green, verde white, bianco""" alt1=alt1.splitlines[] qnum= len[alt1] sol=alt1.copy[] questions=[] answers=[] forqinalt1: q,a=q.split[","] questions.append[q] answers.append[a] qna=[] lettsol =[] letters="abcd" forninrange[qnum]: a1= sol[n].split[","][1] pos=answers.index[a1] answers.pop[pos] a2,a3,a4=answers qq=f"What is the italian word for {questions[n]}" x=[a1,a2,a3, a4] shuffle[x] right=x.index[a1] lettsol.append[letters[right]] qna.append[[qq,x]] answers.insert[pos,a1] # print[*qna, sep="\n"] counter=0 forq inqna: q,a=q print[q] forans ina: print[f"{letters[counter]}]" +ans] counter+=1 counter=0 print[] print["\nSolutions"] counter=0 forss in sol: q,s=ss.split[","] print[q,s," ["+lettsol[counter]+ "]"] counter+=1 |
This is the output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | What isthe italian wordforred a]verde b]bianco c]giallo d]rosso What is the italian wordforyellow a]giallo b]rosso c]verde d]bianco What isthe italian wordforgreen a]bianco b]rosso c]verde d]giallo What isthe italian wordfor white a]bianco b]rosso c]verde d]giallo Solutions red rosso [d] yellow giallo [a] green verde [c] white bianco [a] >>> |
Putting more than 4 questions but having always 4 multiple choices
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | from random import shuffle,sample alt1="""red, rosso yellow, giallo green, verde white, bianco black, nero orange, arancione""" alt1= alt1.splitlines[] qnum=len[alt1] sol=alt1.copy[] questions=[] answers=[] for qinalt1: q,a=q.split[","] questions.append[q] answers.append[a] qna=[] lettsol=[] letters="abcd" fornin range[qnum]: a1=sol[n].split[","][1] pos=answers.index[a1] answers.pop[pos] shuffle[answers] a2,a3,a4=sample[answers,3] qq= f"What is the italian word for {questions[n]}" x=[a1,a2,a3,a4] shuffle[x] right= x.index[a1] lettsol.append[letters[right]] qna.append[[qq,x]] answers.insert[pos,a1] # print[*qna, sep="\n"] counter=0 forqinqna: q,a=q print[q] forans ina: print[f"{letters[counter]}]"+ans] counter+=1 counter= 0 print[] print["\nSolutions"] counter=0 forss insol: q,s= ss.split[","] print[q,s," ["+lettsol[counter]+"]"] counter+=1 |
output
Subscribe to the newsletter for updates
Post written
by
My youtube channel
Twitter:
@pythonprogrammi - python_pygame
Higlighted videos
Speech recognition game
Pygame cheatsheets Videos about this map editor
New free game: Crystal of time
How to make a map editor 1
How to make a map editor 2
How to make a map editor 3
Map editor 1.5
Map editor 1.6
How to make a
videogame map editor with Python - MEP v. 2.1
Map editor for 2d platform game in Python with Pygame v.3.0
How to save a list with pickle with python
Pygame Map Editor 4.0 for Crystals of time
Github repository
Newest
branch [to clone it with git]
git clone --branch cotb2 //github.com/formazione/timecrystals.git