python projet faizan.ppt python game projects

FaizanAhmad293255 260 views 11 slides Jun 19, 2024
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

python projects


Slide Content

PYTHON PROJECT

WORD GUESSING GAME:- The word guessing game, often known as Hangman, is a classic puzzle where players attempt to deduce a hidden word by guessing one letter at a time. Each correct guess reveals all instances of that letter in the word, while incorrect guesses reduce the number of attempts remaining. The game continues until the player either correctly identifies the word or exhausts all guesses. This simple yet engaging game improves vocabulary, spelling, and problem-solving skills, making it popular among both children and adults. Its versatility allows it to be played on paper, in educational software, or as a fun coding exercise.

Word guessing game ALGORITHM:- Initialization Import the random module. Prompt the user to input their name and display a greeting. Define a list of words. Randomly select a word from the list. Initialize an empty string to store user guesses. Set the number of allowed turns to 12. import random name = input("What is your name? ") print("Good Luck ! ", name) words = ['rainbow', 'computer', 'science', 'programming', 'python', 'mathematics', 'player', 'condition', 'reverse', 'water', 'board', 'Faizan'] word = random.choice (words) print("Guess the characters") guesses = '' turns = 12

2.GAME LOOP: The game runs while the number of turns is greater than 0. Initialize a counter failed to count the number of incorrect guesses in the current round. while turns > 0: failed = 0 for char in word: if char in guesses: print(char, end=" ") else: print("_", end=" ") failed += 1 if failed == 0: print("\ nYou Win") print("The word is: ", word) break

3.Word Display Iterate through each character in the chosen word. If the character is in the guesses string, print the character (indicating a correct guess). If the character is not in the guesses string, print an underscore _ (indicating an unguessed letter) and increment the failed counter. If failed is 0 after the loop, it means the user has guessed all characters correctly, so display a win message and the word, then break out of the loop.

4.USER INPUT: Prompt the user to guess a character. Add the guessed character to the guesses string. If the guessed character is not in the chosen word, decrement the turns counter, display a "Wrong" message, and show the remaining number of turns. If turns reaches 0, the loop will end, indicating that the user has used up all their guesses. print() guess = input("guess a character:") guesses += guess if guess not in word: turns -= 1 print("Wrong") print("You have", + turns, 'more guesses')

FLOW CHART :-

PSEUDOCODE:- BEGIN Import random module Prompt user for name Display "Good Luck!" message with user's name Define list of words Randomly select a word from the list Initialize guesses as an empty string Set number of turns to 12 WHILE turns > 0 DO Initialize failed to 0 FOR each character in the chosen word DO

PSEUDOCODE:- IF character is in guesses THEN Print character ELSE Print "_" Increment failed by 1 END IF END FOR IF failed equals 0 THEN Print "You Win" Print the chosen word Break the loop END IF Prompt user to guess a character Add guessed character to guesses Break the loop END IF Prompt user to guess a character Add guessed character to guesses IF guessed character not in chosen word THEN Decrement turns by 1 Print "Wrong" Print remaining number of turns END IF END WHILE IF turns equals 0 THEN Print "You Lose" Print the chosen word END IF END

OUTPUT:-

Submitted by- 1. fAIZAN AHMAD 22SCSE1420025 2.Harsh KUMAR 22SCSE1420088 PYTHON PROJECT SUBMITTED TO- NAMRATA KUMARI