Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Quiz
#1
Hello I am trying to create a basic quiz of 5 questions .
I am really new to programming and so any help with be fantastic .
The code needs to be very basic. Can someone please correct my code . I need the ans1 to be "int"
Many thanks

score= 0#score start with zero
name = input("Enter your name:    ")
ans1= input(int("Q1. What is 3*3 ?")
if ans1== 9:
            print("Correct")
            score=score+1
else:
        print("Incorrect")
Reply
#2
int(some_string) returns the integer value of some_string (if it can be decoded to an integer):

Output:
>>> type('00012') <type 'str'> >>> int('00012') 12 >>> type(int('00012')) <type 'int'>

What happens when the string is not all digits will be addressed when you come to it.
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  QUIZ GUI Form_When admin panel is open, main quiz form is getting freeze Uday 4 707 Aug-25-2023, 08:24 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020