1 Replies - 339 Views - Last Post: 26 October 2017 - 09:50 AM Rate Topic: -----

#1 CurrentGuy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-October 17

Python Quiz Regestration

Posted 26 October 2017 - 05:29 AM

Hey there,

I am trying to create a register code. So basicly im making a quiz and every time a user starts up my program he/she needs to register (making a unique username/pass)
-When registered it will ask to login.

Could anyone help me make the code? My code so far is bellow
#Login
test_u="Amy"
test_p="1234"
loggedIn=False
while loggedIn == False:
    print("Please log in")
    u=input("Enter test username")
    if test_u==u:
        p=input("Enter test password")
# Defining Score variables 
x = 0
score = x
pass
# Question One 
print("When did WW2 finish?")
answer_1 = input("a)2001\nb)1945\nc)1877\nd)1940\n:")
if answer_1.lower() == "b" or answer_1.lower() == "2":
    print("Correct")
    x = x + 1   
else:
    print("Incorrect, the second Worl War ended in 1945")
# Question Two
print("Who was responsilbe of most deaths in World War 1 & 2 ")
answer_2 = input("a)Donald Trump\nb)Adolf Hitler\nc)Tom Cruisend\nd)There were no WAR\n:")
if answer_2.lower() == "b" or answer_2.lower() == "Adolf Hitler":
    print("Correct")
    x = x + 1
else:
    print("Incorrect, It was Adolf Hitler who took around 12 to 14 million lives")
# Question Three
print("True or False... Hitler was a painter")
answer_3 = input(":")
if answer_3.lower() == "true" or answer_3.lower() == "t":
    print("Correct")
    x = x + 1
else:
    print("Incorrect")  
# Question Four
print("What happened in Chernobyl")
answer_4 = input("a)Nuclear Plant exploaded\nb)Water Flood\nc)Alien Envasion\nd)War\n:")
if answer_4.lower() == "a" or answer_4 == "1967":
    print("Correct")
    x = x + 1
else:
    print("Incorrect, the nuclear plant exploaded")
# Question Five 
print("True or False... Everybody knew the reactor will explode")
answer_5 = input(":")
if answer_5.lower() == "false" or answer_5.lower() == "f":
    print("Correct")
    x = x + 1
else:
    print("Incorrect, no one knew it will explode")
#Total Score
score = float(x / 5) * 100
print(x,"out of 5, that is",score, "%")

This post has been edited by ndc85430: 26 October 2017 - 11:17 AM
Reason for edit:: Added code tags. Please do this yourself in future.


Is This A Good Question/Topic? 0
  • +

Replies To: Python Quiz Regestration

#2 albert003  Icon User is offline

  • D.I.C Regular

Reputation: 14
  • Posts: 370
  • Joined: 15-December 14

Re: Python Quiz Regestration

Posted 26 October 2017 - 09:50 AM

Ok, a few things... When you submit a code here you need to use the "insert code snippet" so its easier to read. You have a while loop below with input, print and if statements incorrectly put together. My suggestion is remove the while loop and just use if, elif, else statements if you want to make it multiple choice. If you want the user to input the answer without any other options, I suggest you just use print and below input. That way the user can put in their answer. Because unless you need the program to repeat itself (user inputs wrong answer or an invalid response or you need it to loop) you don't need to use a loop for what you are trying to do in the program.
You also have test_u="Amy" and test_p="1234" but when you want the user to input you have u =input() and p=input(). You never defined what either are and if you run the program it will give that error. I suggest you draw the program using flow charts and decide piece by piece what you want the program to do and behave and then start writing the code.

This post has been edited by albert003: 26 October 2017 - 11:21 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1