0% found this document useful (0 votes)
8 views

Python 1

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Python 1

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

SIMPLE IF STATEMENT:

-----------------------------------
# wap to print a given string if the string is palindrome else ignore. /using
simple if statement/
demo=input("Enter a string:")
if (demo[: :-1]==demo):
print("String is palindrome" )

#wap print the reverse string if length of the string should be odd and last
character of the string should be vowel character. else ignore

di=input("Enter the string:")


if len(di)%2==1 and di[-1] in ['a','e','i','o','u','A','E','I','O','U']:
print(di[: :-1])

# wap to check whether the last digit of the given integer number is lesser than 5
or not . if it
num=int(input("Enter the number:"))
if str(num)[-1]<5:
print(num)

# IF ELSE STATEMENT....
#wap to accept two integers and check whether they are equal or not.
num1=int(input("Enter the value:"))
num2=int(input("Enter the value:"))
if num1==num2:
print("They are equal")
else:
print("They are not equal")

#wap to find greatest of two numbers.


num1=int(input("Enter the value:"))
num2=int(input("Enter the value:"))
if num1>num2:
print("Num1 is Greater...")
else:
print("Num2 is Greater...")

#wap to read the age of a candidate and determine whether the candidate is eligible
to case his own vote.
mani=int(input("Enter the value:"))
if mani>=18:
print("Candidate Eligible for vote..")
else:
print("Candidate Not Eligible for vote..")

#wap to check whether the given 4 values represent prefectly either square or
rectangle or not.else print invalid shape angle.
num1=int(input("Enter the number 1:"))
num2=int(input("Enter the number 2:"))
num3=int(input("Enter the number 3:"))
num4=int(input("Enter the number 4:"))
if (num1==num2==num3==num4) or (num1==num3 and num2==num4):
print("Either square or rectangle")
else:
print("Invalid shape angle")

#wap to check the given number is even number or odd number.


Num=int(input("Enter the value:"))
if Num%2!=1:
print("Even number")
else:
print("Odd number")

#wap to check the given character is lowercase alpbahet or not.


char=input("Enter the Chracter:")
if 'a'<=char<='z':
print("Lowercase Alphabet")
else:
print("Not a Lowercase Alphabet")

#wap to check the given character lowercase alpabahet or uppercase alphabet.


char=input("Enter the Chracter:")
if 'A'<=char<='Z' or 'a'<=char<='z':
print("Lowercase Alphabet or Uppercase Alphabet")
else:
print("invalid character")

#wap to check the given character is lowercase alpbahet or digit.


char=input("Enter the Chracter:")
if 'A'<=char<='Z' or 'a'<=char<='z' or '0'<=char<='9':
print("Alphabet or digit")
else:
print("Invalid")

#wap to check the last digit of the given number is odd. if it is true print the
last digit of the number else print the number as it is.
num=int(input("Enter the Number:"))
if num%2==1:
print(str(num)[-1])
else:
print(num)

#wap to check the given character is special symbol or not.


di=input("Enter the Character:")
if not('A'<=di<='Z' or 'a'<=di<='z' or '0'<=di<='9'):
print("special symbol")
else:
print("not a Special Symbol")

IF ELIF ELSE STATEMENTS:


---------------------------------------------------------------
#wap to find the relations between the two numbers.[greater or lesser or equal].
num1=int(input("Enter the number1:"))
num2=int(input("Enter the number2:"))
if num1>num2:
print("Num1 is greater..")
elif num1<num2:
print("Num2 is greater...")
elif num1==num2:
print("Num1 and Num2 is Equal")

#wap to accept the age of 4 people and display the youngest one.
num1=int(input("Enter the number1:"))
num2=int(input("Enter the number2:"))
num3=int(input("Enter the number3:"))
num4=int(input("Enter the number4:"))
if num1<num2 and num1<num3 and num1<num4:
print("Person1 is Youngest one..")
elif num2<num3 and num2<num4:
print("Person2 is Youngest one...")
elif num3<num4:
print("Person3 is Youngest one...")
else:
print("Person4 is Youngest one...")

#write a program to consolidate the student grade from 5 subject marks.


#print 'A' grade if their percentage is >90 or
#print 'B' grade if their percentage is >75 and <=90 or
#print 'C' grade if their percentage is >65 and <=75 or
#print 'D' grade if their percentage is <=65.
#wap to check whether the given 4 values represent prefectly either square or
rectangle or not.else print invalid shape angle.
num1=int(input("Enter the mark 1:"))
num2=int(input("Enter the mark 2:"))
num3=int(input("Enter the mark 3:"))
num4=int(input("Enter the mark 4:"))
num5=int(input("Enter the mark 5:"))
avg=(num1+num2+num3+num4+num5)/5
if avg>90:
print("Grade A")
elif avg>75 and avg<=90:
print("Grade B")
elif avg>65 and avg<=75:
print("Grade C")
elif avg<=65:
print("Grade D")

#wap to print 'fizz' if the given number divisible by 3 or print 'buzz'


#if the given number divisible by 5 or print 'fizz buzz' if the given number
divisible
#by both 3 and 5 print else print the number as it is.
num=int(input("Enter the number:"))
if num%3==0 and num%5==0:
print("FIZZ BUZZ")
elif num%3==0:
print("FIZZ")
elif num%5==0:
print("BUZZ")
else:
print(num)

You might also like