Welcome to Xenia-Gaming

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Sign in to follow this  
Followers 0
BosnianArmy

Python programming

Hello there folks, long time no speak/topic/forum?

Anyways, I've been studying here and there with school and currently I am learning to program with Python at school and home. Beside Python I study also networking (subnetting and Cisco stuff), Server managing, etc. But we are here for the Python help. The main subject for this little project is that I want to make a small "guessing game" as training.

How the game works:

The game starts with a small storyline and then the program asks how many seconds you need to think for the number that you're about to guess it. After putting the number, the program starts to countdown with a live timer. But the problem is, the program stays with the live timer, doesn't continue with the rest of the code which I'm itching about it how to fix that. But once this is fixed the game should start, you need to guess the number with only 2 guesses (or lifes how ever you see it).

For now I am using greater than and less than function to see if this would work when you enter the right or false number. But seems like what ever number you put in, it will see as a "positive" answer. But it should be that the answer is good or false, good leads of course to you've won the game and false leads to the second guess and from the second guess leads to, Game Over. So here is my code to those who want's to see it:

#Print() = print something
#Integer() = whole numbers --> 5
#Floats = numbers after the comma --> 5.0/5,0
#Strings "" = text --> "Hello World"
#Input() = a user can type something in it
#
#########################################################################
#Introduction storyline
a = "Welcome! Press \"Enter\" to start the game"
print(a)
input() #this should be empty, this leads to the variable "a" from the first line of the code ---> Press enter to start the game

print("First.. a story")
print("Once there was a legend that could guess a number without hesitating, but is that legend true, are you the legend? Let's find out!\n")

#timer before the game starts
import time

while True:
 uin = input(">>How many seconds do you need to guess? Enter here: ")
 try:
 
  when_to_stop = abs(int(uin))
 except KeyboardInterrupt:
		break
 except:
		print("Not a number!")
		
 while when_to_stop > 0:
			m, s = divmod(when_to_stop, 60)
			h, m = divmod(m,60)
			time_left = str(h).zfill(2) + ":" + str(s).zfill(2)
			print(time_left + "\r", end="")
			time.sleep(1)
			when_to_stop -= 1
 print()

#Core code
b = float (input("Guess your number from 0 to 100:"))
c = 3 ** 2
d = c == 9

if d > 9: 
 print("You guessed wrong!\n")
else:
 print("One more chance:")
 

if d < 9:
 print("You guessed wrong!\n")
else:
 print("Game Over!")

Thank you for reading and helping me :) 

Share this post


Link to post
Share on other sites
Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   You have pasted content with formatting.   Remove formatting

×   Your link has been automatically embedded.   Display as a link instead

Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.