The Student Room Group

computer science who can fix my python code

hey guys i got this python code that i dont know how to do a function. it has 2 attempt to answer a question before it moves onto the next. so i want it on the first attempt to earn 10 points but if on the second attempt 5 point but if they get it wrong its 0 points. at the end it prints out their score.
Score = 0
i = 0
while i < 3:
song = input("Guess the song title S... R.....'s' Theme Song?:")
if song == "Seth Rollins Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Seth Rollins Theme Song ? \n A. The Miz \n B. Mickie James \n C. Brock Lesnar \n Answer: ")
if answer1 == "A" or answer1 == "The Miz":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title The U......... Theme Song?:")
if song == "The Undertaker's Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made The Undertaker Theme Song ? \n A. Ultimate Warrior \n B. Shawn Michaels \n C. Kane \n Answer: ")
if answer1 == "B" or answer1 == "Shawn Michaels":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title S.... C... S.... A..... Song?:")
if song == "Stone Cold Steve Austin Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Stone Cold Steve Austin Theme Song ? \n A. Sycho Sid \n B. Bret Hart \n C. The Brothers of Destruction \n Answer: ")
if answer1 == "C" or answer1 == "The Brothers of Destruction":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title C. P... Theme Song?:")
if song == "CM Punk Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made CM Punk Theme Song ? \n A. D - Generation X \n B. Chris Benoit \n C. The NWO \n Answer: ")
if answer1 == "B" or answer1 == "The NWO":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title T..... H Theme Song?:")
if song == "Triple H Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Triple H Theme Song ? \n A. Trish Stratus \n B. Johncena \n C. AJ Style \n Answer: ")
if answer1 == "A" or answer1 == "Trish Stratus":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
print("Your Score out of 10 is",Score )
It looks like a good start. To properly debug you'll need to include the indentation. What problem are you having when running it?
Original post by Lily09897
hey guys i got this python code that i dont know how to do a function. it has 2 attempt to answer a question before it moves onto the next. so i want it on the first attempt to earn 10 points but if on the second attempt 5 point but if they get it wrong its 0 points. at the end it prints out their score.
Score = 0
i = 0
while i < 3:
song = input("Guess the song title S... R.....'s' Theme Song?:")
if song == "Seth Rollins Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Seth Rollins Theme Song ? \n A. The Miz \n B. Mickie James \n C. Brock Lesnar \n Answer: ")
if answer1 == "A" or answer1 == "The Miz":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title The U......... Theme Song?:")
if song == "The Undertaker's Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made The Undertaker Theme Song ? \n A. Ultimate Warrior \n B. Shawn Michaels \n C. Kane \n Answer: ")
if answer1 == "B" or answer1 == "Shawn Michaels":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title S.... C... S.... A..... Song?:")
if song == "Stone Cold Steve Austin Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Stone Cold Steve Austin Theme Song ? \n A. Sycho Sid \n B. Bret Hart \n C. The Brothers of Destruction \n Answer: ")
if answer1 == "C" or answer1 == "The Brothers of Destruction":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title C. P... Theme Song?:")
if song == "CM Punk Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made CM Punk Theme Song ? \n A. D - Generation X \n B. Chris Benoit \n C. The NWO \n Answer: ")
if answer1 == "B" or answer1 == "The NWO":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
song = input("Guess the song title T..... H Theme Song?:")
if song == "Triple H Theme Song":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
i = 0
while i < 3:
answer1 = input("Who made Triple H Theme Song ? \n A. Trish Stratus \n B. Johncena \n C. AJ Style \n Answer: ")
if answer1 == "A" or answer1 == "Trish Stratus":
print("That's the correct song")
break
else:
i += 1
if i == 3:
print("Too many attempts")
break
else:
print(f"That's the wrong song, you have {3-i} attempts left")
print("Your Score out of 10 is",Score )

Did u try running it?
Reply 3
Original post by physgradstudent
It looks like a good start. To properly debug you'll need to include the indentation. What problem are you having when running it?

i don't have any syntax/logic errors but i want to add a scoring system of how at the first attempt of the python program it will give 10 point but at the second attempt there's 5 point but if they get it wrong there is 0 points.
Reply 4
Original post by the_pharaoh
Did u try running it?

guys i don't have errors on this i just want to add a scoring system of how at the first attempt of the python program it will give 10 point but at the second attempt there's 5 point but if they get it wrong there is 0 points.
Original post by Lily09897
guys i don't have errors on this i just want to add a scoring system of how at the first attempt of the python program it will give 10 point but at the second attempt there's 5 point but if they get it wrong there is 0 points.

make a variable that stores the number of atempts then make an if statement with the conditions u just stated also make a total score variable so you can add the score after each question
Reply 6
Original post by the_pharaoh
make a variable that stores the number of atempts then make an if statement with the conditions u just stated also make a total score variable so you can add the score after each question

hey it was so hard for me can you do an example so i can fully understand it plz.
Original post by Lily09897
hey it was so hard for me can you do an example so i can fully understand it plz.

ok let's see so at the beginning you will add the following variables:
no_attempts = 0
total_score = 0

ok this is harder than i thot ok before we do the scoring system I want u to put each question in a loop where the loop gives the user 3 times to answer the question before moving onto the next or if the user gets the answer correct so it will look smthn like this:

while no_attempts < 4 and user_answer != correct_answer:
the question
user_input
is statement to check if the answer is correct
no_attempts = no_attempts + 1
if statement for if the number of attempts is 1:
output
if statement for if the number of attempts is 2:
output
if statement for if the number of attempts is 3:
output


ok i feel like i waffled too much hope u understood
Reply 8
Original post by the_pharaoh
ok let's see so at the beginning you will add the following variables:
no_attempts = 0
total_score = 0

ok this is harder than i thot ok before we do the scoring system I want u to put each question in a loop where the loop gives the user 3 times to answer the question before moving onto the next or if the user gets the answer correct so it will look smthn like this:

while no_attempts < 4 and user_answer != correct_answer:
the question
user_input
is statement to check if the answer is correct
no_attempts = no_attempts + 1
if statement for if the number of attempts is 1:
output
if statement for if the number of attempts is 2:
output
if statement for if the number of attempts is 3:
output


ok i feel like i waffled too much hope u understood

thanks so much as i have copy and pasted the python program could you put your program into mine i am really confused on where to put your program onto mine program.
Original post by Lily09897
thanks so much as i have copy and pasted the python program could you put your program into mine i am really confused on where to put your program onto mine program.

sigh ill tru cuz honestly when i look at pre made code i cant understand anything especially considering u used i instead of acc variable names
Original post by the_pharaoh
sigh ill tru cuz honestly when i look at pre made code i cant understand anything especially considering u used i instead of acc variable names


Original post by the_pharaoh

no_attempts = no_attempts + 1
if statement for if the number of attempts is 1:
output
if statement for if the number of attempts is 2:
output
if statement for if the number of attempts is 3:
output


basically just add this part after every question but put it inside the loop
Reply 11
Original post by the_pharaoh
basically just add this part after every question but put it inside the loop

can you show me an example using one of my question in the python program.
Original post by Lily09897
can you show me an example using one of my question in the python program.


Original post by Lily09897

Score = 0
i = 0
while i < 4 and song != "Seth Rollins Theme Song" :
song = input("Guess the song title S... R.....'s' Theme Song?:")
if song == "Seth Rollins Theme Song":
print("That's the correct song")
i = i + 1
else:
print"that is incorrect try again"
i = i + 1
if i == 1:
print("you scored 10 point")
score = score + 10
elif i == 2:
print("you scored 5 point")
score = score + 5
else:
print("you scored 0 points")
score = score + 0



here u go i completely updated ur code
Reply 13
Original post by the_pharaoh
here u go i completely updated ur code

hey there can you do it with indents its still not work on python saying sytax errors.
Original post by Lily09897
hey there can you do it with indents its still not work on python saying sytax errors.

Nah I'm sorry at this point I'm doing everything for u it's not hard to figure it out plus I'm at school so I can't
This should help.
Reply 16
ok guys i will make it easier just convert this python code to flowchart. i will do the rest please i beg you.

score = 0
i=0
song=0
while (i < 2 and song != "Seth Rollins Theme Song") :
song = input("Guess the song title S... R.....'s' Theme Song?: ")
if (song == "Seth Rollins Theme Song"):
print ("That's the correct song!")
i=i+1
else:
print("That is incorrect, please try again")
i=i+1
if i == 1:
print ("You scored 5 points")
score = score + 10
else:
print ("You scored 0 points")
score = score + 0
Score = 0
i = 0
answer1 = " "
while i < 2 and answer1 != "B and C":
answer1 = input("Who made Seth Rollins Theme Song ? \n A. The Miz \n B. Mickie James \n C. Brock Lesnar \n Answer: ")
if answer1 == "A":
print("That's the correct song!")
if i == 0:
Score = Score + 10
elif i == 1:
Score = Score + 5
else:
Score = Score + 0
i = 5
else:
print("That is not correct")
i = i+1

print ("Your total score is", Score)
Wait.... I wrote that! Give me credit or I will report you!

Quick Reply

Latest

Trending

Trending