python if else elif plus bonus
check if ur eligible to vote
ag=int(input('enter an age')) if ag >= 18: print('yoo u can vote') else: print('na fam not yet')
Accept the age, sex ('M', 'F'), number of days and display the wages accordingly AgeSexWage/day>=18 and <30M700F750>=30 and <=40M800F850
age=int(input("Enter your age")) sex=input("Enter sex ") nd = int(input("Enter number of days")) if age >=18 and age < 30 and sex.upper( ) == 'M': amt = nd*700 print("Total wages is: ", amt) elif age >=18 and age < 30 and sex.upper( ) == 'F': amt = nd*750 print("Total wages is: ", amt) elif age >=30 and age <= 40 and sex.upper( ) == 'M': amt = nd * 800 print("Total wages is: ", amt) elif age >=30 and age <= 40 and sex.upper( ) == 'F': amt = nd * 850 print("Total wages is: ", amt) else: print("Enter appropriate age")
check is number is uppercase, lowercase, or special character
ch = input("Enter a character to check:") if ord(ch)>=65 and ord(ch)<=90: print("The character", ch, " is an uppercase letter") elif ord(ch)>=97 and ord(ch)<=122: print("The character", ch, " is a lowercase letter") elif ord(ch)>=48 and ord(ch)<=57: print("The character", ch, " is a digit") else: print("The character", ch, " is a special character")
u can sit in exam is attendance is over 75%
ch=int(input('classes held ')) ca=int(input('classes atended ')) x=ca/ch*100 if x>75: print('u can exam') elif x<=75: print('no exam lol')
program to determine if character is vowel
char=input("Enter any character ") vow="aeiouAEIOU" if char in vow: print("Entered character is vowel") else: print("Entered character is not vowel")
places and their capitals
city = input("Enter name of the city: ") if city.lower()=="delhi": print("Monument name is : Red Fort") elif city.lower()=="agra": print("Monument name is : Taj Mahal") elif city.lower()=="jaipur": print("Monument name is : Jal Mahal") else: print("Enter correct name of city")
how many L's in hello world
count = 0 for letter in 'Hello World': if(letter == 'l'): count += 1 print(count,'letters found')
counts 1 to 21
ct=1 while ct<21: print(ct) ct=ct+1
a program to check whether a number is prime or not
k=0 num1 = int(input("Enter any number")) if num1 == 0 or num1 == 1: k=1 for i in range(2,num1): if num1%i == 0: k = 1 if k==1: print("number is not prime") else: print("number is prime")
tells if number is one, two, or three digits
n = int(input("Enter any number:")) if n>0 and n<10: print("One digit number") elif n>10 and n<100: print("Two digit number") elif n>100 and n<1000: print("Three digit number") else: print("More than three digit number")
diff outputs for diff words
n1=input("put a word ") if n1.lower( )=="pog": print('mmm') elif n1.lower( )=='pogg': print('mm') elif n1.lower( )=='poggg': print('m') else: print('oh nvm')
if input is pog, produce mmm as output
n1=input("put a word ") if n1.lower( )=="pog": print('mmm') else: print('oh nvm')
Accept three numbers from the user and display the second largest number.
n1=int(input("put a number ")) n2=int(input('put a number ')) n3=int(input('put a number ')) if (n1>n2 and n1<n3) or (n1<n2 and n1>n3): print('the second largest is', n1) if (n2>n1 and n2<n1) or (n2<n1 and n2>n1): print('the second largest is', n2) if (n3>n1 and n3<n2) or (n3<n1 and n3>n2): print('the second largest is', n3) else: print('pls enter non repeating numbers')
A toy vendor supplies three types of toys: Battery Based Toys, Key-based Toys, and Electrical Charging Based Toys. The vendor gives a discount of 10% on orders for battery-based toys if the order is for more than Rs. 1000. On orders of more than Rs. 100 for key-based toys, a discount of 5% is given, and a discount of 10% is given on orders for electrical charging based toys of value more than Rs. 500. Assume that the numeric codes 1,2 and 3 are used for battery based toys, key-based toys, and electrical charging based toys respectively. Write a program that reads the product code and the order amount and prints out the net amount that the customer is required to pay after the discount.
n=int(input('enter code(1, 2, or 3) ')) if n==1: bt=int(input('enter amount purchased ')) if bt>=1000: print(bt*90/100) else: print(bt) elif n==2: kt=int(input('enter amount purchased ')) if kt>=100: print(kt*95/100) else: print(kt) elif n==3: et=int(input('enter amount purchased ')) if et>=500: print(et*90/100) else: print(et)
make any number absolute
n=int(input('enter number ')) if n<0: print(n*-1) else: print(n)
times table for a number
n=int(input('enter number: ')) count=1 while count<=10: product=n*count print(n, 'x', count, '=', product) count=count+1
Accept the marked price from the user and calculate the Net amount as(Marked Price - Discount) to pay according to following criteria: Marked PriceDiscount>1000020%>7000 and <=1000015%<=700010%
na=0 d=0 mp=int(input("Enter marked price")) if mp > 10000: d = 20/100*mp if mp > 7000 and mp <= 10000: d = 15/100*mp if mp <= 7000: d = 10/100*mp na = mp-d print("Net amount to pay ", na)
which is bigger number
num1 = int(input("Enter first number")) num2 = int(input("Enter second number")) if num1 > num2: print("bigger number is :", num1) else: print("bigger number is :", num2)
which is smaller number
num1 = int(input("Enter first number")) num2 = int(input("Enter second number")) if num1 > num2: print("smaller number is :", num2) else: print("smaller number is :", num1)
Write a program to accept two numbers and mathematical operators and perform operation accordingly. Like: Enter First Number: 7 Enter Second Number : 9 Enter operator : + Your Answer is : 16
num1=int(input("Enter first number")) num2=int(input("Enter second number")) op=input("Enter mathematical operator") if op=='+': print("Result is ", num1+num2) if op=='-': print("Result is ", num1-num2) if op=='*': print("Result is ", num1*num2) if op=='/': print("Result is ", num1/num2) if op=='%': print("Result is ", num1%num2) if op=='**': print("Result is ", num1**num2) if op=='//': print("Result is ", num1//num2)
is number positive or negative
num1=int(input('enter a number')) if num1 >= 0: print('positive') else: print('negative')
is number divisible by 2 and 3
num1=int(input('enter a number')) if num1%2==0 and num1%3==0: print('divisible') else: print('not divisible')
is number even or odd
num1=int(input('enter a number')) if num1%2==0: print('even') else: print('odd')
which of 3 numbers is largest
num1=int(input('enter a number')) num2=int(input('enter a number')) num3=int(input('enter a number')) if num1 > num2 and num1 > num3: print("Greatest number is ", num1) if num2 > num1 and num2 > num3: print("Greatest number is ", num2) if num3 > num2 and num3 > num1: print("Greatest number is ", num3)
is number u entered 3 digits?
num=(input("Enter any number")) if len(num) !=3: print("Enter three digit number") else: print("Middle digit is ",(int(num)%100//10))
Write a program to accept a number from 1 to 7 and display the name of the day like 1 for monday, 2 for sunday and so on
num=int(input("enter a number between 1 & 7: ")) if num==1: print("monday") elif num==2: print("Tuesday") elif num==3: print("Wednesday") elif num==4: print("Thursday") elif num==5: print("Friday") elif num==6: print("Saturday") elif num==7: print('sunday') else: print('enter a number between 1 and 7')
a code that uses greater than > and less than or equal to <=
num=int(input('enter a number')) if num > 5 and num <= 10: print('inbetween') else: print('outside')
which of 4 is oldest
p1=int(input('enter an age')) p2=int(input('enter an age')) p3=int(input('enter an age')) p4=int(input('enter an age')) if p1>p2 and p1>p3 and p1>p4: print('oldest is ', p1) if p2>p1 and p2>p3 and p2>p4: print('oldest is ', p2) if p3>p1 and p3>p2 and p3>p4: print('oldest is ', p3) if p4>p1 and p4>p2 and p4>p3: print('oldest is ', p4)
simple palendrome checker
pali=input('enter a palindrome ') stringlength=len(pali) # calculate length of the list slicedString=pali[stringlength::-1] # slicing if slicedString==pali: print('true') elif slicedString!=pali: print('false')
program that calculates ur grade
per = int(input("Enter marks")) if per > 90: print("Grade is A") if per > 80 and per <=90: print("Grade is B") if per >=60 and per <= 80: print("Grade is C") if per < 60: print("Grade is D")
cost of bike and tax
pr=int(input("Enter the price of car")) if pr > 100000: tax = 15/100*pr elif pr >50000 and pr <=100000: tax = 10/100*pr else: tax = 5/100*pr print("Tax to be paid ",tax)
Accept three sides of triangle and check whether the triangle is possible or not. (triangle is possible only when sum of any two sides is greater than 3rd side)
s1=int(input("Enter First side of triangle")) s2=int(input("Enter Second side of triangle")) s3=int(input("Enter Third side of triangle")) if s1+s2 > s3 and s2 + s3 > s1 and s1 + s3 > s2: print("Triangle is possible") else: print("Triangle not possible")
Accept three sides of a triangle and check whether it is an equilateral, isosceles or scalene triangle. Note : An equilateral triangle is a triangle in which all three sides are equal. A scalene triangle is a triangle that has three unequal sides. An isosceles triangle is a triangle with (at least) two equal sides.
s1=int(input("Enter first side of triangle")) s2=int(input("Enter second side of triangle")) s3=int(input("Enter third side of triangle")) if s1==s2 and s2 == s3: print("Equilateral triangle") if (s1==s2 and s2!=s3) or (s2==s3 and s2!=s1) or (s1==s3 and s1!=s2): print("Isosceles Triangle") if s1!=s2 and s1!=s3 and s2!=s3: print("Scalene Triangle")
Accept the electric units from user and calculate the bill according to the following rates. First 100 Units : Free Next 200 Units : Rs 2 per day. Above 300 Units : Rs 5 per day. if number of unit is 500 then total bill = 0 +400 + 1000 = 1400
s1=int(input("Enter units ")) if s1<=199: print(s1) elif s1>=200 and s1<=299: eq=s1*2 print(eq) elif s1>=300 and s1<=499: eq=s1*5 print(eq) elif s1>=500: eq=s1+1400 print(eq)
A company decided to give bonus to employee according to following criteria: Time period of Service Bonus More than 10 years 10% >=6 and <=10 8% Less than 6 years 5% Ask user for their salary and years of service and print the net bonus amount.
sal=int(input('whats ur salary ')) yr=int(input('whats ur years ')) if yr>10: bns = 10/100*sal elif yr>=6 and yr<=10: bns = 8/100*sal elif yr<6: bns = 5/100*sal print('bonus is ', bns)
Accept the temperature in degree Celsius of water and check whether it is boiling or not (boiling point of water in 100 oC.
temp=int(input('enter a temp')) if temp>=100: print('boiling') else: print('not boiling')
treepersqkm is a dictionary showing the tree number of countries per square kilometer for random countries with sizeable population numbers. Write a function named "moretrees" that returns a list of country names with more than 20.000 trees per square kilometer.
treepersqkm = {"Finland": 90652, "Taiwan": 69593, "Japan": 49894, "Russia": 41396, "Brazil": 39542, "Canada": 36388, "Bulgaria": 24987, "France": 24436, "Greece": 24323, "United States": 23513, "Turkey": 11126, "India": 11109, "Denmark": 6129, "Syria": 534, "Saudi Arabia": 1} #Type your answer here. def moretrees(dict): list = [] for i in dict: if dict[i]>20000: list.append(i) else: pass return list print(moretrees(treepersqkm))
Accept the following from the user and calculate the percentage of class attended: a. Total number of working days b. Total number of days for absent After calculating percentage show that, If the percentage is less than 75, than student will not be able to sit in exam
wrk = int(input('enter working days ')) ab = int(input('enter absent days ')) per = (wrk-ab)/wrk*100 if per>75: print('exam time') else: print('u fail')
tells if a year is leap year or not
yr=int(input("Enter the year")) if yr%4==0: print("Entered year is leap year") else: print("Entered year is not a leap year")
only give workers 5% bonus if they work more than 5 yrs
yr=int(input('how many years u work ')) sal=int(input('whats ur salary ')) n=sal*0.05 if yr>=5: print('ur bonus is', n) else: print('no bonus for u')