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
| print("Please think of a number between 0 and 100!") | |
| low = 0 | |
| high = 100 | |
| ans = int((low + high) / 2) | |
| while True: | |
| print("Is your secret number %d " %ans) | |
| userguess = input("Enter 'h' to indicate the guess is too high. Enter 'l' to indicate the guess is too low. Enter 'c' to indicate I guessed correctly. ") | |
| if userguess == 'h': | |
| high = ans | |
| elif userguess == 'l': |
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, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
| print [i for i in a if (i % 2 == 0)] |
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
| str = raw_input("Enter the string to be checked ") | |
| if (str[::1])==(str[::-1]): | |
| print "Palindrome" | |
| else: | |
| print "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
| list = [1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 13, 14 , 1, 2, 3, 5, 7] | |
| num = int(raw_input("Enter the numbers to be dispalyed in the list)) | |
| new_list = [] | |
| for i in list: | |
| if i < num : | |
| new_list.append(i) | |
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
| num = int(raw_input("Enter a number")) | |
| if num % 2 == 0 | |
| print "The number is even." | |
| else: | |
| print "The number is odd." |
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 age : ")) | |
| new_age = 2017 + 100 - age | |
| print "%s will turn 100 years old in %r year " % (name, new_age) |