user2694486
user2694486

Reputation: 1

i want to setup a score count in python 3.3.2

 **count = 0**
 player = input("Player Name: ")
 print("WELCOME TO MY QUIZ %s" % player, )
 print("Would You like to play the quiz ??")
 start = input()
 if start == "Yes" or start == "yes":
    print("Lets Start %s" % player, )
    print("Q1. What is the capital of India ?")
    print("A. Delhi")
    print("B. Mumbai")
    q1 = input()
    if q1 == "A":
         **count += 1**
    else:
         print("")
    print("Q2. How many states are there in India ?")
    print("A. 28")
    print("B. 29")
    q2 = input()
    if q2 == "B":
         count += 1
    else:
         print("")
    print("Q3. What is the capital of Maharashtra ?")
    print("A. Delhi")
    print("B. Mumbai")
    q3 = input()
    if q3 == "B":
        count += 1
    else:
        print("")
    ***print("You got"),str(count)+"/3 right!"***
else:
    print("Thank You, Goodbye")

I have done this so far but im not getting the proper score any help ? I dont get any output regarding the score or the count i only get "You Got: that's it

Upvotes: 0

Views: 11378

Answers (3)

Joey
Joey

Reputation: 1

I think you do it like this. (Not Sure)

score = 0
ans = input('What is 2+2')
if ans == '4':
    print('Good')
    score = +1
else:
    print('Wrong')
    score = +0

To Show The Score Do This

print(score, 'Out Of 1')

Upvotes: 0

unutbu
unutbu

Reputation: 879113

print("You got"), str(count)+"/3 right!"

is a tuple. print("You got") is a function call in Python3; it prints to the screen but returns None. str(count)+"/3 right!" is a string. The comma between the two expressions makes the combined expression a tuple. You don't see the second part because it was never passed to the print function. Python just evaluates the expression and then leaves it to get garbage collected since it is not assigned to anything.

So to fix your code with minimal changes, move the parenthesis and remove the comma:

print("You got" + str(count) + "/3 right!")

But building strings with + is not recommended. Matt Bryant shows the preferred way. Or, since you are using a Python version greater than 2.6, you can shorten it a wee little bit:

print("You got {}/3 right!".format(count))

The {} gets replaced by count. See The Format String Syntax for more info.


Also, instead of multiple calls to print:

print("Lets Start %s" % player, )
print("Q1. What is the capital of India ?")
print("A. Delhi")
print("B. Mumbai")

you can print a single multiline string:

print("""Lets Start {}
Q1. What is the capital of India ?
A. Delhi
B. Mumbai""".format(player))

Fewer function calls makes it faster, and it is more readable and requires less typing.

Upvotes: 0

Matt Bryant
Matt Bryant

Reputation: 4961

You are not using print() correctly.

Print the score with

print("You got {0}/3 right!".format(count))

Upvotes: 1

Related Questions