</pre> #This is my adventure game import time def scene1(): print('You are standing on a trail in a forrest') print('Before you the trail splits in two') print('Which way will you go right or left?''\n') def makeChoice(): choice = '' while choice != '1' and choice != '2': print('Press 1 followed by enter to choose the first option') print('Press 2 followed by enter to choose the second option') choice = input() return choice def scene2A(): print('\n''You come to a stream with bridge') print('You can cross and follow the trail that leads from the bridge') print('or follow the trail that leads along the nearside of the river''\n') def scene2B(): print('\n''you come to a steep hill') print('you can climb over the hill') print('or you can follow the trail which leads around it','\n') def goodEnd(): print('You travel along until you hear people''\n') time.sleep(1) print('They sound like they are having fun''\n') time.sleep(1) print('You suddenly see them and realise it\'s your friends having a picnic') print ('they share their food and drinks with you and you have a great time') def badEnd(): print('You travel along''\n') time.sleep(1) print ('on and on''\n') time.sleep(1) print('you have no idea where you are''\n') time.sleep(1) print('suddenly you realise you are back where you started') #main program starts here playAgain = 'yes' while playAgain == 'yes' or playAgain == 'y': scene1() #use the makeChoice function to get #the player to decide which way to go firstChoice = makeChoice() #this if else statement will show the next #scene based on the players choice if firstChoice == '1': scene2A() else: scene2B() secondChoice = makeChoice() #this if else statement will show the next #scene based on the players choice if secondChoice == '1': goodEnd() else: badEnd() print('Do you want to play again? (yes or no)') playAgain = input()
We also took a look at Snap which is an extended re-implementation of Scratch that allows us to build our own blocks. Snap is available at http://snap.berkeley.edu/. We compared our Python code to a similar Snap script.
We compared Python functions to Scratch blocks and made a few blocks of our own using Snap. Here are my slides from today. python session5