Loop & Control Statements in Python Programs - Helpwalaa - Free IT Updates & Opportunities

New Updates

Loop & Control Statements in Python Programs

Programs:

1. WAP to check given number is Palindrome or not
2. Write a menu driven program to perform following operation
3. 1. Addition, 2. Subtraction, 3. Multiplication, 4. Float Division,  5. Integer Division,   6. Exponent, 7. Exit

 4. WAP to generate following pattern




Palindrome

string = input("Please Enter String or Number : ")

if(string == string[:: - 1]):
   print("It is Palindrome")
else:
   print("It is not Palindrome")
 
Output :-



Menu Driven Operations

print("Menu Driven Operations")
print("1.Addition")
print("2.Substraction")
print("3.Multiplication")
print("4.Division")

ch=int(input("Enter Choice(1-4): "))

if ch==1:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a+b
    print("Sum = ",c)
elif ch==2:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a-b
    print("Difference = ",c)
elif  ch==3:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a*b
    print("Product = ",c)
elif ch==4:
    a=int(input("Enter A:"))
    b=int(input("Enter B:"))
    c=a/b
    print("Quotient = ",c)
else:
    print("Invalid Choice")


Output :-





Pattern :-

k = 13
GB = 1
for i in range(0, 5):
    for j in range(0, k):
        print(end=" ")
    k = k - 2
    for j in range(0, GB):
        print("* ", end="")
    GB = GB + 1
    print()

Output :-




Most Popular