code improvement /u/Human-Bass-1609 Python Education

Hi im very new to python, like i literally just started learning this week and im a complete beginner with no prior programming experience

i tried to make a little quiz using what ive learned so far, but id like some tips to improve and shorten my code. ik its got a lot of issues and it isnt perfect but thats why im posting it here

any assistance would be appreciated (:

# making a quiz questions = ["Q1: Is the earth round?", "Q2: Can llama's moo?", "Q3: do lions roar?"] score = 0 Q1 = 0 answer = ["yes", "no", "yes"] for i, question in enumerate(questions): print(question) if i == Q1: user_input = input().lower().strip() if user_input == answer[Q1]: print("correct") new_score = score + 1 else: print("wrong") new_score = score if i == Q1 + 1: user_input = input().lower().strip() if user_input == answer[Q1 + 1]: print("correct") newnew_score = new_score + 1 else: print("wrong") newnew_score = new_score if i == Q1 + 2: user_input = input().lower().strip() if user_input == answer[Q1 + 2]: print("correct") newnewnew_score = newnew_score + 1 else: print("wrong") newnewnew_score = newnew_score print("your total score is: ", newnewnew_score, "/3", sep="") 

submitted by /u/Human-Bass-1609
[link] [comments]

​r/learnpython Hi im very new to python, like i literally just started learning this week and im a complete beginner with no prior programming experience i tried to make a little quiz using what ive learned so far, but id like some tips to improve and shorten my code. ik its got a lot of issues and it isnt perfect but thats why im posting it here any assistance would be appreciated (: # making a quiz questions = [“Q1: Is the earth round?”, “Q2: Can llama’s moo?”, “Q3: do lions roar?”] score = 0 Q1 = 0 answer = [“yes”, “no”, “yes”] for i, question in enumerate(questions): print(question) if i == Q1: user_input = input().lower().strip() if user_input == answer[Q1]: print(“correct”) new_score = score + 1 else: print(“wrong”) new_score = score if i == Q1 + 1: user_input = input().lower().strip() if user_input == answer[Q1 + 1]: print(“correct”) newnew_score = new_score + 1 else: print(“wrong”) newnew_score = new_score if i == Q1 + 2: user_input = input().lower().strip() if user_input == answer[Q1 + 2]: print(“correct”) newnewnew_score = newnew_score + 1 else: print(“wrong”) newnewnew_score = newnew_score print(“your total score is: “, newnewnew_score, “/3″, sep=””) submitted by /u/Human-Bass-1609 [link] [comments] 

Hi im very new to python, like i literally just started learning this week and im a complete beginner with no prior programming experience

i tried to make a little quiz using what ive learned so far, but id like some tips to improve and shorten my code. ik its got a lot of issues and it isnt perfect but thats why im posting it here

any assistance would be appreciated (:

# making a quiz questions = ["Q1: Is the earth round?", "Q2: Can llama's moo?", "Q3: do lions roar?"] score = 0 Q1 = 0 answer = ["yes", "no", "yes"] for i, question in enumerate(questions): print(question) if i == Q1: user_input = input().lower().strip() if user_input == answer[Q1]: print("correct") new_score = score + 1 else: print("wrong") new_score = score if i == Q1 + 1: user_input = input().lower().strip() if user_input == answer[Q1 + 1]: print("correct") newnew_score = new_score + 1 else: print("wrong") newnew_score = new_score if i == Q1 + 2: user_input = input().lower().strip() if user_input == answer[Q1 + 2]: print("correct") newnewnew_score = newnew_score + 1 else: print("wrong") newnewnew_score = newnew_score print("your total score is: ", newnewnew_score, "/3", sep="") 

submitted by /u/Human-Bass-1609
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *