From 9d80becb46c572e2ec019463c3c066cb9b9c5db4 Mon Sep 17 00:00:00 2001 From: Bianca Date: Tue, 3 Apr 2018 15:43:46 -0400 Subject: [PATCH 1/2] Add files via upload Uploading some Python game tutorials --- Dragon.py | 45 +++++++++++++++++++++++++++++++++++++++ DrawCircle.py | 18 ++++++++++++++++ GuesstheNumber.py | 36 +++++++++++++++++++++++++++++++ HelloWorld(GamingBook).py | 5 +++++ Jokes.py | 16 ++++++++++++++ Spiro.py | 26 ++++++++++++++++++++++ 6 files changed, 146 insertions(+) create mode 100644 Dragon.py create mode 100644 DrawCircle.py create mode 100644 GuesstheNumber.py create mode 100644 HelloWorld(GamingBook).py create mode 100644 Jokes.py create mode 100644 Spiro.py diff --git a/Dragon.py b/Dragon.py new file mode 100644 index 0000000..d962360 --- /dev/null +++ b/Dragon.py @@ -0,0 +1,45 @@ +import random +import time + +def displayIntro(): + print('You are in a land full of dragons. In front of you,') + print('you see two caves. In one cave, the dragon is friendly') + print('and will share his treasure with you. The other dragon') + print('is greedy and hungry, and will eat you on sight.') + print() + +def chooseCave(): + cave ='' + while cave != '1' and cave != '2': + print('Which cave will you go into? (1 or 2)') + cave = input() + + return cave + +def checkCave(chosenCave): + print('You approach the cave...') + time.sleep(2) + print('It is dark and spooky...') + time.sleep(2) + print('A large dragon jumps out in front of you! He opens his jaws and...') + print() + time.sleep(2) + + friendlyCave = random.randint(1, 2) + + if chosenCave == str(friendlyCave): + print('Gives you his treasure!') + else: + print('Gobbles you down in one bite!') + +playAgain = 'yes' +while playAgain == 'yes' or playAgain == 'y': + displayIntro() + + caveNumber = chooseCave() + + checkCave(caveNumber) + + print('Do you want to play again? (yes or no)') + playAgain = input() + diff --git a/DrawCircle.py b/DrawCircle.py new file mode 100644 index 0000000..fccd5f9 --- /dev/null +++ b/DrawCircle.py @@ -0,0 +1,18 @@ +import math +import turtle + +# draw the circle using turtle +def drawCircleTurtle(x, y, r): + # move to the start of circle + turtle.up() + turtle.setpos(x + r, y) + turtle.down() + + # draw the circle + for i in range(0, 365, 5): + a = math.radians(i) + turtle.setpos(x + r*math.cos(a), y + r*math.sin(a)) + +drawCircleTurtle(100, 100, 50) +turtle.mainloop() + diff --git a/GuesstheNumber.py b/GuesstheNumber.py new file mode 100644 index 0000000..14d89f2 --- /dev/null +++ b/GuesstheNumber.py @@ -0,0 +1,36 @@ +# This is a guess the number game. +import random + +guessesTaken = 0 + +print('Hello! What is your name?') +myName = input() + +number = random.randint(1,20) +print('Well, ' + myName + ', I am thinking of a number between 1 and 20.') + +while guessesTaken < 6: + print('Take a guess.') + guess = input() + guess = int(guess) + + guessesTaken = guessesTaken + 1 + + if guess < number: + print('Your guess is too low.') + + if guess > number: + print('Your guess is too high.') + + if guess == number: + break + +if guess == number: + guessesTaken = str(guessesTaken) + print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!') + +if guess != number: + number = str(number) + print('Nope. The number I was thinking of was ' + number) + + diff --git a/HelloWorld(GamingBook).py b/HelloWorld(GamingBook).py new file mode 100644 index 0000000..b622760 --- /dev/null +++ b/HelloWorld(GamingBook).py @@ -0,0 +1,5 @@ +# This program says hello and asks for my name. +print('Hello world!') +print('What is your name?') +myName = input() +print('It is good to meet you, ' +myName) diff --git a/Jokes.py b/Jokes.py new file mode 100644 index 0000000..b92c939 --- /dev/null +++ b/Jokes.py @@ -0,0 +1,16 @@ +print('What do you get when you cross a snowman with a vampire?') +input() +print('Frostbite!') +print() +print('What do dentists call an astronaut\'s cavity?') +input() +print('A black hole!') +print() +print('Knock, knock.') +input() +print("Who's there?") +input() +print('Interrupting cow.') +input() +print('Interrupting cow wh', end='') +print('-MOO!') diff --git a/Spiro.py b/Spiro.py new file mode 100644 index 0000000..e44884c --- /dev/null +++ b/Spiro.py @@ -0,0 +1,26 @@ +# a class that draws a Spirograph +class Spiro: + + # constructor + def _init_(self, xc, yc, col, R, r, l): + + # create the turtle object + self.t = turtle.Turtle() + # set the cursor shape + self.t.shape('turtle') + # set the step in degrees + self.step = 5 + # set the drawing complete flag + self.drawingComplete = False + + # set the parameters + self.setparams(xc, yc, col, R, r, l) + + # initialize the drawing + self.restart() + + # set the parameters + def setparams(self, xc, yc, col, R, l): + # the Spirograph parameters + self.xc = xc + self.yc = yc From d9abba85ff36510ef44fd6451bac03b515aa4166 Mon Sep 17 00:00:00 2001 From: Bianca Date: Tue, 3 Apr 2018 16:26:04 -0400 Subject: [PATCH 2/2] Update Jokes.py Adding time breaks. --- Jokes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Jokes.py b/Jokes.py index b92c939..d350a6a 100644 --- a/Jokes.py +++ b/Jokes.py @@ -1,11 +1,17 @@ +import time + +print('Ready for some jokes? Press "Enter" to continue.') +input() print('What do you get when you cross a snowman with a vampire?') input() print('Frostbite!') print() +time.sleep(1) print('What do dentists call an astronaut\'s cavity?') input() print('A black hole!') print() +time.sleep(1) print('Knock, knock.') input() print("Who's there?")