Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
February 24th, 2013, 09:33 PM
 TSZAR
Registered User

Join Date: Feb 2013
Posts: 2
Time spent in forums: 11 m 6 sec
Reputation Power: 0
Python Help

Hi,
I've been working on a particular math-quiz game as an introductory project to python scripting. In this program, I use strings of random integers to create new problems every time a question comes up.

However, in one of these chains, the if-then statement that dictates what the program will do depending on if an answer is right or wrong has been malfunctioning. The statement completely bypasses the "correct" option and goes to the "incorrect" route (these are not hard either, its painfully obvious like 8+5=? questions)

The program piece that is malfunctioning looks like this:

import random
Qb=random.randint(1, 10)
Qbb=random.randint(1, 10)
print ('Question 2' + str (Qb) +' + ' + str (Qbb) + ' = ?')
Qba=input()
Qbaa = Qb + Qbb
if Qba == ('Qbaa'):
print ('Correct! + 25 to score!')
Score = Score + 25
print (Score)
else:
print ('Incorrect')

What is causing the correct path to be bypassed?

#2
February 24th, 2013, 10:25 PM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,218
Time spent in forums: 1 Month 3 Weeks 2 Days 18 h 51 m 46 sec
Reputation Power: 455
Code:
```# python3
import random
Qb=random.randint(1, 10)
Qbb=random.randint(1, 10)
print ('Question 2:   ' + str (Qb) +' + ' + str (Qbb) + ' = ?') # separate the question number please!
Qba=input()      # Qba is a string
Qbaa = Qb + Qbb  # Qbaa is an integer
if Qba == str(Qbaa):   # compare as strings.   str(Qbaa)
print ('Correct! + 25 to score!')
Score = Score + 25
print (Score)
else:
print ('Incorrect')```
__________________
[code]Code tags[/code] are essential for python code!

#3
February 24th, 2013, 11:07 PM
 TSZAR
Registered User

Join Date: Feb 2013
Posts: 2
Time spent in forums: 11 m 6 sec
Reputation Power: 0
Quote:
 Originally Posted by b49P23TIvg Code: ```# python3 import random Qb=random.randint(1, 10) Qbb=random.randint(1, 10) print ('Question 2: ' + str (Qb) +' + ' + str (Qbb) + ' = ?') # separate the question number please! Qba=input() # Qba is a string Qbaa = Qb + Qbb # Qbaa is an integer if Qba == str(Qbaa): # compare as strings. str(Qbaa) print ('Correct! + 25 to score!') Score = Score + 25 print (Score) else: print ('Incorrect')```

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Python Help