{{ message }}

Instantly share code, notes, and snippets.

# Devendra0110/01 Character Input.py

Last active Aug 16, 2020
solutions for exercise on site https://www.practicepython.org/
 import datetime now = datetime.datetime.now() print("Enter your name and age") name = input('Name:') age = int(input('Age :')) remainingYears = 100 - age print("Enter the no. of times you want to see the output") messageCount = int(input("-->")) message = "In "+str(remainingYears + now.year)+" you'll be 100 year old" print(messageCount * (message+"\n"))
 print("Enter a number to check if it is odd or even") num = int(input('-->')) if num%4==0: print(str(num)+' modulo 4 is 0.') elif num%2==0: print(str(num)+' is an even number' ) else: print(str(num)+' is an odd number' ) print("Enter two number to check if second is evenly divide into first") num1 = int(input('num1:')) num2 = int(input('num2:')) if num1 % num2==0: print(str(num1)+ ' is evenly divisble by '+str(num2)) else: print(str(num1)+ ' is not evenly divisble by '+str(num2))
 a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] b = [element for element in a if element<5] print(b) print('Enter the number') maxNumber = int(input("-->")) userList = [element for element in a if element < maxNumber] print(userList)
 print("Enter any number") num = int(input('num:')) count =0 divisibles = [] for i in range(1,int(num/2)+1): if num%i==0 : divisibles.append(i) print(divisibles)
 import random a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] c = list(set(a) & set(b)) print('Common elements: '+str(c)) a = random.sample(range(0,40),10) b = random.sample(range(0,40),10) c = list(set(a) & set(b)) print("list a:"+str(a)) print("list b:"+str(b)) if len(c) > 0: print('Common elements: '+str(c)) else: print('No common elements in random list')
 print("Enter a string to check if it's palindrome or not") givenString = input("-->").lower() if givenString == givenString[::-1]: print("String is palindrome") else: print("String is not palindrome")
 a = [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] evens = [num for num in a if num%2==0] print(evens)