Skip to content

add game3 on random #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions python-exercises/game_3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import random
x = random.randint(1, 10)
a = -1
print('Guess the number from 1 to 10')
while a != x:
a = int(input('>>>'))
if a == x:
print('You win')
elif a < x:
print('The number is greater')
else:
print('The number less than the guess')
83 changes: 83 additions & 0 deletions python-exercises/game_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#importing the time module
import time

#welcoming the user
name = raw_input("What is your name? ")

print "Hello, " + name, "Time to play hangman! \n"


#wait for 1 second
time.sleep(1)

print "Start guessing..."
time.sleep(0.5)

#here we set the secret
word = "secret"

#creates an variable with an empty value
guesses = ''

#determine the number of turns
turns = 10

# Create a while loop

#check if the turns are more than zero
while turns > 0:

# make a counter that starts with zero
failed = 0

# for every character in secret_word
for char in word:

# see if the character is in the players guess
if char in guesses:

# print then out the character
print char,

else:

# if not found, print a dash
print "_",

# and increase the failed counter with one
failed += 1

# if failed is equal to zero

# print You Won
if failed == 0:
print "You won"

# exit the script
break

print

# ask the user go guess a character
guess = raw_input("guess a character:")

# set the players guess to guesses
guesses += guess

# if the guess is not found in the secret word
if guess not in word:

# turns counter decreases with 1 (now 9)
turns -= 1

# print wrong
print "Wrong"

# how many turns are left
print "You have", + turns, 'more guesses'

# if the turns are equal to zero
if turns == 0:

# print "You Loose"
print "You Loose"