├── README.md ├── calender.py ├── dice_roll.py ├── password_generator.py ├── dice_roll.txt ├── password.py ├── Contact_Book.py ├── guess the number.py ├── passwor_generator.txt ├── rockpapercissor.py ├── guess_number.py └── Hangman.py /README.md: -------------------------------------------------------------------------------- 1 | # PythonProgramming -------------------------------------------------------------------------------- /calender.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | 4 | yy=int(input('Enter the year (like : 2010) : ')) # year 5 | mm=int(input("Enter the number of month (like : 10) : ")) # month 6 | 7 | #display the calendar 8 | print(calendar.month(yy,mm)) -------------------------------------------------------------------------------- /dice_roll.py: -------------------------------------------------------------------------------- 1 | #Rolling the dice 2 | 3 | import random 4 | min = 1 5 | max = 6 6 | 7 | roll_again = "yes" 8 | 9 | while roll_again == "yes" or roll_again == "y": 10 | print ("Rolling the dices...") 11 | print ("The values are....") 12 | print (random.randint(min, max)) 13 | print (random.randint(min, max)) 14 | 15 | roll_again =input("Roll the dices again? : ") 16 | -------------------------------------------------------------------------------- /password_generator.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | 4 | def get_random_string(length): 5 | # choose from all lowercase letter 6 | letters = string.ascii_lowercase 7 | result_str = ''.join(random.choice(letters) for i in range(length)) 8 | print("Random string of length", length, "is:", result_str) 9 | 10 | get_random_string(8) 11 | get_random_string(6) 12 | get_random_string(4) 13 | -------------------------------------------------------------------------------- /dice_roll.txt: -------------------------------------------------------------------------------- 1 | How it works 2 | This is a classic “roll the dice” program. 3 | We will be using the random module for this,since we want to randomize the numberswe get from the dice. 4 | 5 | We set two variables (min and max) , lowest and highest number of the dice. 6 | We then use a while loop, so that the user can roll the dice again. 7 | 8 | The roll_again can be set to any value, but here it’s set to “yes” or “y”, 9 | but you can also add other variations to it. 10 | -------------------------------------------------------------------------------- /password.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | pas=['a','b','c','d','e','f','g', 4 | 'h','i', 'j','k', 'l','m','n', 5 | 'o','p', 'q','r','s','t','u', 6 | 'v','w', 'x', 'y','z','A','B', 7 | 'C','D','E','F','G','H','I', 8 | 'J','K','L','M','N','0','P', 9 | 'Q','R','S','T','U','V','W', 10 | 'X','Y', 'Z', '1','2','3', '4', 11 | '5','6','7','8','9','0','&', 12 | '!','@','#','$','%','_'] 13 | 14 | password="" 15 | for i in range(8): 16 | password=password+random.choices(pas)[0] 17 | 18 | print("Your password : ",password) -------------------------------------------------------------------------------- /Contact_Book.py: -------------------------------------------------------------------------------- 1 | names = [] 2 | phone_numbers = [] 3 | num = 3 4 | 5 | 6 | for i in range(num): 7 | name = input("Name: ") 8 | phone_number = input("Phone Number: ") # for convert to int => int(input("Phone Number: ")) 9 | 10 | names.append(name) 11 | phone_numbers.append(phone_number) 12 | 13 | print("\nName\t\t\tPhone Number\n") 14 | 15 | for i in range(num): 16 | print("{}\t\t\t{}".format(names[i], phone_numbers[i])) 17 | 18 | search_term = input("\nEnter search term: ") 19 | 20 | print("Search result:") 21 | 22 | if search_term in names: 23 | index = names.index(search_term) 24 | phone_number = phone_numbers[index] 25 | print("Name: {}, Phone Number: {}".format(search_term, phone_number)) 26 | 27 | else: 28 | print("Name Not Found") -------------------------------------------------------------------------------- /guess the number.py: -------------------------------------------------------------------------------- 1 | import random #importing random module to genertae random int value 2 | n = 20 #random genertaed value will be between 0-20 3 | to_be_guessed=int (n *random.random()) + 1 #generating random value and stored in the variable 4 | 5 | guess = 0#initializing the guess number to 0 6 | for i in range(10):#number of tries a user can make 7 | while guess != to_be_guessed:#condition for while loop 8 | 9 | guess = int (input("New number: "))#taking the input of the number that u have guessed 10 | 11 | if guess > 0: 12 | if guess>to_be_guessed: 13 | print("Number too large") 14 | 15 | elif guess 10: 31 | 32 | raise ValueError("Please guess a number within the given range") 33 | 34 | if int(guess) == random_number: 35 | 36 | print("Nice! You got it!") 37 | 38 | attempts += 1 39 | 40 | attempts_list.append(attempts) 41 | 42 | print("It took you {} attempts".format(attempts)) 43 | 44 | play_again = input("Would you like to play again? (Enter Yes/No) ") 45 | 46 | attempts = 0 47 | 48 | show_score() 49 | 50 | random_number = int(random.randint(1, 10)) 51 | 52 | if play_again.lower() == "no": 53 | 54 | print("That's cool, have a good one!") 55 | 56 | break 57 | 58 | elif int(guess) > random_number: 59 | 60 | print("It's lower") 61 | 62 | attempts += 1 63 | 64 | elif int(guess) < random_number: 65 | 66 | print("It's higher") 67 | 68 | attempts += 1 69 | 70 | except ValueError as err: 71 | 72 | print("Oh no!, that is not a valid value. Try again...") 73 | 74 | print("({})".format(err)) 75 | 76 | else: 77 | 78 | print("That's cool, have a good one!") 79 | 80 | if __name__ == '__main__': 81 | 82 | start_game() -------------------------------------------------------------------------------- /Hangman.py: -------------------------------------------------------------------------------- 1 | # Python Program to illustrate 2 | # Hangman Game 3 | import random 4 | from collections import Counter 5 | 6 | someWords = '''apple banana mango strawberry 7 | orange grape pineapple apricot lemon coconut watermelon 8 | cherry papaya berry peach lychee muskmelon''' 9 | 10 | someWords = someWords.split(' ') 11 | # randomly choose a secret word from our "someWords" LIST. 12 | word = random.choice(someWords) 13 | 14 | if __name__ == '__main__': 15 | print('Guess the word! HINT: word is a name of a fruit') 16 | 17 | for i in word: 18 | # For printing the empty spaces for letters of the word 19 | print('_', end = ' ') 20 | print() 21 | 22 | playing = True 23 | # list for storing the letters guessed by the player 24 | letterGuessed = '' 25 | chances = len(word) + 2 26 | correct = 0 27 | flag = 0 28 | try: 29 | while (chances != 0) and flag == 0: #flag is updated when the word is correctly guessed 30 | print() 31 | chances -= 1 32 | 33 | try: 34 | guess = str(input('Enter a letter to guess: ')) 35 | except: 36 | print('Enter only a letter!') 37 | continue 38 | 39 | # Validation of the guess 40 | if not guess.isalpha(): 41 | print('Enter only a LETTER') 42 | continue 43 | elif len(guess) > 1: 44 | print('Enter only a SINGLE letter') 45 | continue 46 | elif guess in letterGuessed: 47 | print('You have already guessed that letter') 48 | continue 49 | 50 | 51 | # If letter is guessed correctly 52 | if guess in word: 53 | k = word.count(guess) #k stores the number of times the guessed letter occurs in the word 54 | for _ in range(k): 55 | letterGuessed += guess # The guess letter is added as many times as it occurs 56 | 57 | # Print the word 58 | for char in word: 59 | if char in letterGuessed and (Counter(letterGuessed) != Counter(word)): 60 | print(char, end = ' ') 61 | correct += 1 62 | # If user has guessed all the letters 63 | elif (Counter(letterGuessed) == Counter(word)): # Once the correct word is guessed fully, 64 | # the game ends, even if chances remain 65 | print("The word is: ", end=' ') 66 | print(word) 67 | flag = 1 68 | print('Congratulations, You won!') 69 | break # To break out of the for loop 70 | break # To break out of the while loop 71 | else: 72 | print('_', end = ' ') 73 | 74 | 75 | 76 | # If user has used all of his chances 77 | if chances <= 0 and (Counter(letterGuessed) != Counter(word)): 78 | print() 79 | print('You lost! Try again..') 80 | print('The word was {}'.format(word)) 81 | 82 | except KeyboardInterrupt: 83 | print() 84 | print('Bye! Try again.') 85 | exit() --------------------------------------------------------------------------------