├── .gitignore ├── README.md ├── prime_number.py ├── Duplicate_in_list.py ├── Password Authentication using Python.py ├── Treasure game.py └── hangman.py /.gitignore: -------------------------------------------------------------------------------- 1 | /demo.txt 2 | /hello.py -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # python_program for beginners 2 | python concept 3 | -------------------------------------------------------------------------------- /prime_number.py: -------------------------------------------------------------------------------- 1 | n=int(input()) 2 | for i in range(2,n//2): #we can check the number by 2 for better optimization, 3 | if n%i==0: 4 | print("not prime number") 5 | break 6 | else: 7 | print("prime number") 8 | -------------------------------------------------------------------------------- /Duplicate_in_list.py: -------------------------------------------------------------------------------- 1 | list1=list(map(int,input().split())) 2 | list2=set(list1) #set is a built-in function which remove duplicate values 3 | if len(list1)==len(list2): 4 | print("No Duplicate") 5 | else: 6 | print(list2) 7 | 8 | -------------------------------------------------------------------------------- /Password Authentication using Python.py: -------------------------------------------------------------------------------- 1 | import getpass 2 | database = {"sudhar": "123456", "sudhar": "654321"} 3 | username = input("Enter Your Username : ") 4 | password = getpass.getpass("Enter Your Password : ") 5 | for i in database.keys(): 6 | if username == i: 7 | while password != database.get(i): 8 | password = getpass.getpass("Enter Your Password Again : ") 9 | break 10 | print("Verified") 11 | -------------------------------------------------------------------------------- /Treasure game.py: -------------------------------------------------------------------------------- 1 | print("Welcome to treasure island.") 2 | print("Your mission is to find the treasure") 3 | choice=input('you\'re at a crossroad, where do you wnat to go? type"left" or "right".').lower() 4 | if choice=="left": 5 | choice1=input('You\'ve come to lake. There is an island in the middle of the lake.type"wait" to wait for a boat . type"swim " to swim across.').lower() 6 | if choice1=="wait": 7 | choice2=input("You arrive at the island unharmed.There is a house with 3 doors.one red,one yellow,one blue.which colour do you choose? ").lower() 8 | if choice2=="red": 9 | print("Its's a room full of fire.Game over.") 10 | elif choice2=="yellow": 11 | print("You found the treasure! You win") 12 | elif choice2=="blue": 13 | print("You enter a room of beast.Game over.") 14 | else: 15 | print("You choose a door that doesn't exist .Game over.") 16 | else: 17 | print("You got attacked by an angry fish.game over.") 18 | 19 | else: 20 | print("You fell into a hole.Game over") 21 | 22 | -------------------------------------------------------------------------------- /hangman.py: -------------------------------------------------------------------------------- 1 | class Hangman(): 2 | def __init__(self): 3 | print "Welcome to 'Hangman', are you ready to die?" 4 | print "(1)Yes, for I am already dead.\n(2)No, get me outta here!" 5 | user_choice_1 = raw_input("->") 6 | 7 | if user_choice_1 == '1': 8 | print "Loading nooses, murderers, rapists, thiefs, lunatics..." 9 | self.start_game() 10 | elif user_choice_1 == '2': 11 | print "Bye bye now..." 12 | exit() 13 | else: 14 | print "I'm sorry, I'm hard of hearing, could you repeat that?" 15 | self.__init__() 16 | 17 | def start_game(self): 18 | print "A crowd begins to gather, they can't wait to see some real" 19 | print "justice. There's just one thing, you aren't a real criminal." 20 | print "No, no. You're the wrong time, wrong place type. You may think" 21 | print "you're dead, but it's not like that at all. Yes, yes. You've" 22 | print "got a chance to live. All you've gotta do is guess the right" 23 | print "words and you can live to see another day. But don't get so" 24 | print "happy yet. If you make 6 wrong guess, YOU'RE TOAST! VAMANOS!" 25 | self.core_game() 26 | 27 | def core_game(self): 28 | guesses = 0 29 | letters_used = "" 30 | the_word = "pizza" 31 | progress = ["?", "?", "?", "?", "?"] 32 | 33 | while guesses < 6: 34 | guess = raw_input("Guess a letter ->") 35 | 36 | if guess in the_word and not in letters_used: 37 | print "As it turns out, your guess was RIGHT!" 38 | letters_used += "," + guess 39 | self.hangman_graphic(guesses) 40 | print "Progress: " + self.progress_updater(guess, the_word, progress) 41 | print "Letter used: " + letters_used 42 | elif guess not in the_word and not(in letters_used): 43 | guesses += 1 44 | print "Things aren't looking so good, that guess was WRONG!" 45 | print "Oh man, that crowd is getting happy, I thought you" 46 | print "wanted to make them mad?" 47 | letters_used += "," + guess 48 | self.hangman_graphic(guesses) 49 | print "Progress: " + "".join(progress) 50 | print "Letter used: " + letters_used 51 | else: 52 | print "That's the wrong letter, you wanna be out here all day?" 53 | print "Try again!" 54 | 55 | 56 | 57 | def hangman_graphic(self, guesses): 58 | if guesses == 0: 59 | print "________ " 60 | print "| | " 61 | print "| " 62 | print "| " 63 | print "| " 64 | print "| " 65 | elif guesses == 1: 66 | print "________ " 67 | print "| | " 68 | print "| 0 " 69 | print "| " 70 | print "| " 71 | print "| " 72 | elif guesses == 2: 73 | print "________ " 74 | print "| | " 75 | print "| 0 " 76 | print "| / " 77 | print "| " 78 | print "| " 79 | elif guesses == 3: 80 | print "________ " 81 | print "| | " 82 | print "| 0 " 83 | print "| /| " 84 | print "| " 85 | print "| " 86 | elif guesses == 4: 87 | print "________ " 88 | print "| | " 89 | print "| 0 " 90 | print "| /|\ " 91 | print "| " 92 | print "| " 93 | elif guesses == 5: 94 | print "________ " 95 | print "| | " 96 | print "| 0 " 97 | print "| /|\ " 98 | print "| / " 99 | print "| " 100 | else: 101 | print "________ " 102 | print "| | " 103 | print "| 0 " 104 | print "| /|\ " 105 | print "| / \ " 106 | print "| " 107 | print "The noose tightens around your neck, and you feel the" 108 | print "sudden urge to urinate." 109 | print "GAME OVER!" 110 | self.__init__() 111 | 112 | def progress_updater(self, guess, the_word, progress): 113 | i = 0 114 | while i < len(the_word): 115 | if guess == the_word[i]: 116 | progress[i] = guess 117 | i += 1 118 | else: 119 | i += 1 120 | 121 | return "".join(progress) 122 | 123 | game = Hangman() 124 | 125 | 126 | 127 | 128 | 129 | --------------------------------------------------------------------------------