Skip to content
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
66 changes: 45 additions & 21 deletions Animal-Guess/animalguess.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,49 @@
import random

def check_guess(guess, answer):
global score
still_guessing = True
"""Check user's guess and return True if correct."""
attempt = 0
while still_guessing and attempt < 3:
while attempt < 3:
if guess.lower() == answer.lower():
print("Correct Answer")
score = score + 1
still_guessing = False
print("✅ Correct Answer!\n")
return True
else:
if attempt < 2:
guess = input("Sorry Wrong Answer, try again")
attempt = attempt + 1
if attempt == 3:
print("The Correct answer is ",answer )

score = 0
print("Guess the Animal")
guess1 = input("Which bear lives at the North Pole? ")
check_guess(guess1, "polar bear")
guess2 = input("Which is the fastest land animal? ")
check_guess(guess2, "Cheetah")
guess3 = input("Which is the larget animal? ")
check_guess(guess3, "Blue Whale")
print("Your Score is "+ str(score))
attempt += 1
if attempt < 3:
guess = input("❌ Wrong! Try again: ")
print(f"The correct answer is: {answer}\n")
return False


def main():
print("🐾 Welcome to the Animal Guessing Game! 🐾")
print("You have 3 attempts for each question.\n")

questions = {
"Which bear lives at the North Pole?": "polar bear",
"Which is the fastest land animal?": "cheetah",
"Which is the largest animal?": "blue whale",
"Which animal is known as the king of the jungle?": "lion",
"Which animal can sleep standing up?": "horse"
}

score = 0
# Randomize question order
for question, answer in random.sample(list(questions.items()), 3):
guess = input(question + " ")
if check_guess(guess, answer):
score += 1

print(f"🎯 Your final score is: {score}/{len(questions)}")

# Option to play again
replay = input("\nDo you want to play again? (yes/no): ")
if replay.lower().startswith('y'):
print("\nRestarting game...\n")
main()
else:
print("Thanks for playing! 🦋")


if __name__ == "__main__":
main()
15 changes: 14 additions & 1 deletion Digital_Clock/digital_clock.py
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove the changes made to this file. Each PR should be isolated to one single purpose, and the changes made to this file don't belong here.

You can perform interactive rebasing to remove the commit that contains the changes to this file. And if you use rebasing, your commit history will change, so force-push your changes to this branch.

Important

If you're stuck or unable to do it, please ping @iamwatchdogs in the conversation tab of this PR.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, font=None):
self.set_font(font)
self.add_header()
self.add_clock()
self.add_date() # ✅ Added new method to show date
self.update_time_on_clock()

def create_window(self):
Expand Down Expand Up @@ -39,6 +40,19 @@ def add_clock(self):
'times', 90, 'bold'), bg='blue', fg='white')
self.clock.grid(row=2, column=2, padx=620, pady=250)

def add_date(self):
"""Add a date label below the clock."""
self.date_label = Label(self.window, font=('times', 40, 'bold'), bg='black', fg='white')
self.date_label.grid(row=3, column=2)
self.update_date_on_clock()

def update_date_on_clock(self):
"""Update the date displayed below the clock."""
currentDate = time.strftime("%d-%b-%Y")
self.date_label.config(text=currentDate)
# Update every midnight (24*60*60*1000 ms)
self.date_label.after(86400000, self.update_date_on_clock)

def update_time_on_clock(self):
"""Update the time displayed on the clock every second."""
currentTime = time.strftime("%H:%M:%S")
Expand All @@ -53,4 +67,3 @@ def start(self):
if __name__ == "__main__":
clock = DigitalClock()
clock.start()