Osbornezo's Profile
Reputation: 0
Apprentice
- Group:
- New Members
- Active Posts:
- 15 (0.06 per day)
- Joined:
- 28-September 12
- Profile Views:
- 92
- Last Active:
Oct 18 2012 02:39 PM- Currently:
- Offline
Previous Fields
- Country:
- NZ
- OS Preference:
- Windows
- Favorite Browser:
- Who Cares
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- PC
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Restarting a program
Posted 5 Oct 2012
midknight51, on 05 October 2012 - 12:03 AM, said:Could you try the code yourself? It goes super weird on me, it repeats the intro line untill i exit the programDoes it work? The indention looks weird but as long as the indention is right in your code you should be fine. If it gives and error let me know. -
In Topic: Restarting a program
Posted 4 Oct 2012
midknight51, on 04 October 2012 - 11:41 PM, said:Wait. now it goes in at the start of the program? Here is my code so far then:Ah, I see what I did, it is looping but because the print function is within the while loop, it will say that no matter what input the user provides. So you have to move that print function outside of the while loop. Or just get rid of it all together.
Updated code:
restart = '1' #Restart now equals the string '1' at the beginning of your code. while restart == '1': #While restart is equal to the string '1': #Your program here: restart = input("Would you like to play again? Enter 1 for YES and 2 for NO.") #Now the user enters 1 or 2. If the user enters 1, the while loops restarts, restarting your program. #If they press 2 the program exits the while loop. #Note the indentation of the next line to tell the shell it is now OUT of the while loop. print "Thanks for playing Mason's Who Wants To Be A Millionaire New Zealand Edition!"
# Mason Osborne # 10 question multi choice answer game import time restart = '1' while restart == '1': print "Hi there, welcome to Mason's who wants to be a millionaire New Zealand Edition" # Welcomes user time.sleep(3) def main(): name=raw_input( "Please type in your name then hit Enter") # Asks for name print '\nHello there', name, 'I hope you have fun. Enjoy and good luck!!' # Prints the stored name with an encouraging message print '\nReady' time.sleep(1) print '\n3' time.sleep(1) print '\n2' time.sleep(1) print '\n1' time.sleep(1) print'\nGo!' Question1() time.sleep(2) Question2() time.sleep(2) Question3() time.sleep(2) Question4() time.sleep(2) Question5() time.sleep(2) Question6() time.sleep(2) Question7() time.sleep(2) Question8() time.sleep(2) Question9() time.sleep(2) Question10() start = time.time() def Question1(): print '\nWhat is the capital of New Zealand?' print '\nA) Invercargill' print '\nB) Wellington' print '\nC) Dunedin' print '\nD) Auckland' ans1=raw_input ('Answer: ') if ans1 == 'A' or ans1=='a': print 'Wrong!' elif ans1 == 'B'or ans1=='b': print 'Correct! Wellington is the Capital of New Zealand, Nice work!' elif ans1 == 'C'or ans1== 'c': print 'Wrong!' elif ans1 == 'D'or ans1== 'd': print 'Wrong!' def Question2(): print'\nWho is the captain of the AllBlacks Rugby team?' print '\nA) Daniel Carter' print '\nB) Andrew Hore' print '\nC) Conrad Smith' print '\nD) Richie McCaw' ans2=raw_input ('Answer: ') if ans2 == 'A' or ans2=='a': print 'Wrong!' elif ans2 == 'B'or ans2=='b': print 'Wrong!' elif ans2 == 'C'or ans2== 'c': print 'Wrong!' elif ans2 == 'D'or ans2== 'd': print 'Correct, Richie McCaw is the AllBlacks captain! Awesome work!' def Question3(): print'\nWhat is the weather in dunedin?' print '\nA) Miserable' print '\nB) Sunny' print '\nC) Heat Wave' print '\nD) Windy' ans3=raw_input ('Answer: ') if ans3 == 'A' or ans3=='a': print 'Dunedins weather is miserable as always' elif ans3 == 'B'or ans3=='b': print 'Wrong!' elif ans3 == 'C'or ans3== 'c': print 'Wrong!' elif ans3 == 'D'or ans3== 'd': print 'Wrong!' def Question4(): print"\nWhat is New Zealand's iconic food?" print '\nA) Scones' print '\nB) Pizza' print '\nC) Pavalova' print '\nD) Fish & Chips' ans4=raw_input ('Answer: ') if ans4 == 'A' or ans4=='a': print 'Wrong!' elif ans4 == 'B'or ans4=='b': print 'Wrong!' elif ans4 == 'C'or ans4== 'c': print 'Well done! Pavalova is New Zealands iconic food' elif ans4 == 'D'or ans4== 'd': print 'Wrong!' def Question5(): print'\nThe Maori name for the New Zealand is Aoteroa, what does this mean in english?' print '\nA) Land of the golden sand' print '\nB) Land of the long white cloud' print '\nC) Land of the cloudy mountain' print '\nD) Land of rain and wind' ans5=raw_input ('Answer: ') if ans5 == 'A' or ans5=='a': print 'Wrong!' elif ans5 == 'B'or ans5=='b': print 'Correct!Aotearoa means Land of the long white cloud' elif ans5 == 'C'or ans5== 'c': print 'Wrong!' elif ans5 == 'D'or ans5== 'd': print 'Wrong!' def Question6(): print'\nWellington is the capital of New Zealand, what is the nickname of the parliament building?' print '\nA) The Rattery' print '\nB) The Ants Nest' print '\nC) The Beehive' print '\nD) The Rabbits Warren' ans6=raw_input ('Answer: ') if ans6 == 'A' or ans6=='a': print 'Wrong!' elif ans6 == 'B'or ans6=='b': print 'Wrong!' elif ans6 == 'C'or ans6== 'c': print 'Correct! The Beehive is the nickname for the New Zealand Parliament' elif ans6 == 'D'or ans6== 'd': print 'Wrong!' def Question7(): print'\nWhat is the highest mountain in New Zealand?' print '\nA) Mount Cook' print '\nB) Mount Taranaki' print '\nC) Mount Dobson' print '\nD) Mount Tasman' ans7=raw_input ('Answer: ') if ans7 == 'A' or ans7=='a': print 'Correct! Mount Cook is the highest mountain in New Zealand' elif ans7 == 'B'or ans7=='b': print 'Wrong!' elif ans7 == 'C'or ans7== 'c': print 'Wrong!' elif ans7 == 'D'or ans7== 'd': print 'Wrong!' def Question8(): print'\nNew Zealands population is roughly?' print '\nA) 6 million' print '\nB) 2.8 million' print '\nC) 4 million' print '\nD) 7.3 milllion' ans8=raw_input ('Answer: ') if ans8 == 'A' or ans8=='a': print 'Wrong!' elif ans8 == 'B'or ans8=='b': print 'Wrong!' elif ans8 == 'C'or ans8== 'c': print 'Correct! The population of New Zealand is roughly 4 million people!' elif ans8 == 'D'or ans8== 'd': print 'Wrong!' def Question9(): print"\nWhich New Zealand reptile is the world's most ancient animal?" print '\nA)Tuatara' print '\nB)Komodo Dragon' print '\nC)New Zealand Alligator' print '\nD)King Cobra' ans9=raw_input ('Answer: ') if ans9 == 'A' or ans9=='a': print 'Correct! The Tuatara is the most ancient animal and is from New Zealand!' elif ans9 == 'B'or ans9=='b': print 'Wrong!' elif ans9 == 'C'or ans9== 'c': print 'Wrong!' elif ans9 == 'D'or ans9== 'd': print 'Wrong!' def Question10(): print'\nName the body of water that separates the North and South Islands' print '\nA)Bass Strait' print '\nB)Tasman Sea' print '\nC)Foveaux Strait' print '\nD)Cook Strait' ans10=raw_input ('Answer: ') if ans10 == 'A' or ans10=='a': print 'Wrong!' elif ans10 == 'B'or ans10=='b': print 'Wrong!' elif ans10 == 'C'or ans10== 'c': print 'Wrong!' elif ans10 == 'D'or ans10== 'd': print 'Correct! The body of water that separates the North and South Islands is the Cook Strait!' time.sleep(1) end = round(start - time.time(), 2) print "you completed this quiz in " + str(end) + " seconds." restart = input("Would you like to play again? Enter 1 for YES and 2 for NO.") main()
It doesnt like the indented blocks -
In Topic: Restarting a program
Posted 4 Oct 2012
midknight51, on 03 October 2012 - 05:47 AM, said:restart = '1' #Restart now equals the string 1, not the integer 1. while restart == '1': #While restart is equal the the string 1: restart = input("Would you like to play again? Please enter '1' for YES or '2' for NO: ") print "Thanks for playing Mason's Who Wants To Be A Millionaire New Zealand Edition!"
That would be your fix using your precise code. Another way you could do it would be putting your entire program into a while loop where a variable named...let's say, playAgain was equal to true. Then at the end of your game there is a section of code that asks if the player would liek to play again. If they say yes, then nothing happens to playAgain as it is already true and your program restarts. If they say no then playAgain turns to False.
Example:
playAgain = True answer = '' while playAgain: #Once upon a time I was falling in love. #But now im only falling apart. #There's nothing I can do. #A total ecplise of the heart. #After your program has been written... answer = input('Would you like to play again? (yes/no):').lower() if answer == 'n' or 'no': playAgain = False #End program, if the user typed y or yes or poop or anything else, playAgain remains true and the program starts over, if they type n or no then playAgain turns to false and the program exits the while loop.
I know there are better ways to do this, but the large while loop is what I typically do for any sort of game that requires a 'restart' function.
When i press 1 to play again it just says thanks for playing, its like its not actually looping -
In Topic: Restarting a program
Posted 29 Sep 2012
JackOfAllTrades, on 29 September 2012 - 08:56 AM, said:Would you show me how using my code? its not compulsary homework or anything i just want to add it in to one of my assignments so i can learn it and use it in more of my programs, im still quite new and this is rather dauntingThe return value of input() is a string, which you are comparing against an int. Convert the result of your input value to an int before assigning to the restart variable.
-
In Topic: Timing a quiz question
Posted 29 Sep 2012
I have noticed something, it gives it in negatives, like you did this quiz in -243 seconds
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
- Location:
- New Zealand
- Full Name:
- Mason Osborne
- Programming Languages:
- Python
Contact Information
- E-mail:
- Click here to e-mail me
Friends
Osbornezo hasn't added any friends yet.
|
|


Find Topics
Find Posts
View Reputation Given
|
Comments
Osbornezo has no profile comments yet. Why not say hello?