This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import random | |
| rand_num = random.randint(1, 9) | |
| user_guess = int(raw_input("Guess a number between 1 to 9: ")) | |
| attempts = 0 | |
| while user_guess != rand_num: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| p1_call = raw_input("Player 1, Enter rock/paper/scissors: ") | |
| p2_call = raw_input("Player 2, Enter rock/paper/scissors: ") | |
| def rock_paper_scissors(player_1, player_2): | |
| a_list = ["rock", "paper", "scissors"] | |
| while player_1 not in a_list or player_2 not in a_list: | |
| print "Invalid input. Please give a valid input." | |
| player_1 = raw_input("Player 1, Enter rock/paper/scissors: ") | |
| player_2 = raw_input("Player 2, Enter rock/paper/scissors: ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [x ** 2 for x in range(1, 11)] | |
| a_even = [] | |
| for i in a: | |
| if i % 2 == 0: | |
| a_even.append(i) | |
| print a_even |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string = raw_input("Enter a string: ") | |
| reverse_string = string[::-1] | |
| if string == reverse_string: | |
| print "The given string is a palindrome." | |
| else: | |
| print "The given string is NOT a palindrome." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name = raw_input("Enter your name: ") | |
| age = int(raw_input("Enter your age in numerals: ")) | |
| hundred_years = 2017 + 100 - age | |
| print "Hello %s! You will turn 100 years old in the year %s." %(name, hundred_years) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Prgram which returns list of common elements in two lists. | |
| list_a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
| list_b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
| # Removing duplicates. | |
| def remove_duplicates(any_list): | |
| new_list = [] | |
| for item in any_list: | |
| if item not in new_list: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
| b = [] | |
| for i in a: | |
| if i < 5: | |
| b.append(i) | |
| print b |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| number = int(raw_input("Enter a number: ")) | |
| if number % 2 == 0: | |
| print (str(number) + " is an even number.") | |
| else: | |
| print (str(number) + " is an odd number.") |