Skip to content
Tester
# Start coding here...
#This is a guess the number game
import random
guessesTaken = 0
print('Hello! What is your name?')
myName= 'Brenda'
number = random.randint(1,350)
print('Well, ' + myName + ', I am thinking of a number between 1 and 350.')
for guessesTaken in range(6):
print('Take a guess.') # Four spaces in front of print''
guess = 8
guess = int(guess)
if guess < number:
print('Your guess is too low.') #eight spaces in front of 'print'
if guess > number:
print('Your guess is too high.')
if guess == number:
break
if guess == number:
guessesTaken = str(guessesTaken + 1)
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 + '.')
import random # when using a random number generator of any kind or when needing a random number always import RANDOM file (lowercase in code)
random.randint(1,20)
int('43') #Overwitten due to other int()
4 + int(8) # if youre adding an int() then put the # you wanna add/sub/mult/div, in the front of the equation to avoid error.
#DragonRealm dragon.py
import random
import time
def displayIntro():
print('''You are in a land full of dragons. In front of you are two caves. In one cave, the dragon is friendly and will share his treasure with you. The other dragon 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 = random.randint(1 or 2)
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('Givese tou his treasure!')
else:
print('Gobbles you down in one bite!')
playAgain = 'yes'
while playAgain == 'yes' or playAgain == 'y':
displayIntro()
caveNumber = 1
checkCave(caveNumber)
print('Do you want to play again? (yes or no)')
playAgain = 'y'