Skip to content
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

Number guessing game #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,45 @@ This will allow you to `git pull upstream master` in order to get updates. When
# Copyright

© Ken Youens-Clark 2019-2020


import random
import math
# Taking Inputs
lower = int(input("Emter Lower bound:- "))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspelled word


# Taking Inputs
upper = int(input("Enter Upper bound:- "))

# generating random number between
# the lower and upper
x = random.randint(lower, upper)
print("\n\tYou've only ", round(math.log(upper - lower + 1, 2))," chances to guess the integer!\n")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use f string to minimize comma and quotation marks


# Initializing the number of guesses.
count = 0

# for calculation of minimum number of
# guesses depends upon range
while count < math.log(upper - lower + 1, 2):
count += 1

# taking guessing number as input
guess = int(input("Guess a number:- "))

# Condition testing
if x == guess:
print("Congratulations you did it in ", count, " try")
# Once guessed, loop will break
break
elif x > guess:
print("You guessed too small!")
elif x < guess:
print("You Guessed too high!")

# If Guessing is more than required guesses,
# shows this output.
if count >= math.log(upper - lower + 1, 2):
print("\nThe number is %d"%x)
print("\tBetter Luck Next time!")