Facebook
From JOYCE, 1 Year ago, written in Python.
Embed
Download Paste or View Raw
Hits: 169
  1. '''
  2. Write an interactive python program to perform the following.
  3. 1.To input 2 integers and generate 1 random numbers.
  4. 2.To pass an integer argument and return the no: of digits.
  5. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  6. 4.Exit
  7. '''
  8. import random
  9. def generate():
  10.      lw=int(input('Enter lower range'))
  11.      up=int(input('Enter Upper range'))
  12.      s=0
  13.      for i in range(10):
  14.           print(random.randint(lw,up),end='\\t')
  15. def countdigit(n):
  16.      c=0
  17.      while n!=0:
  18.           c+=1
  19.           n//=10
  20.      print('the number of digits is',c)
  21. def calculator(a,op,b):
  22.      if op=='+':
  23.           s=a+b
  24.           print('Sum is',s)
  25.      elif op=='-':
  26.           d=a-b
  27.           print('Difference is',d)
  28.      elif op=='*':
  29.           m=a*b
  30.           print('Multiplication is',m)
  31.      elif op=='/':
  32.           s=a+b
  33.           print('Quotient is',qt)
  34. n=int(input('Enter a number'))
  35. a=int(input('Enter a number to calculator'))
  36. b=int(input('Enter a number to calculator'))
  37. op=input('Enter operator')
  38. ch=0
  39. while ch!=4:
  40.     print("\n","-"*20)
  41.     print("1.To input 2 integers and generate 1 random numbers\n2.To pass an integer argument and return the no: of digits.\n3.To pass 2 integer argument and operator to perform operations of a calculator.\n4.Exit")
  42.     ch=int(input("Enter choice:"))
  43.     if ch==1:
  44.         generate()
  45.     elif ch==2:
  46.         countdigit(n)
  47.     elif ch==3:
  48.         calculator(a,op,b)
  49.     elif ch!=4:
  50.         print("INVALID CHOICE")