Facebook
From JOYCE, 9 Months ago, written in Python.
Embed
Download Paste or View Raw
Hits: 185
  1. Q.2)'''Write an interactive python program to perform the following.
  2. 1.To input 2 integers and generate 1 random numbers.
  3. 2.To pass an integer argument and return the no: of digits.
  4. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  5. 4.Exit'''
  6.  
  7. import random
  8. def generate():
  9.      for i in range(10):
  10.           print(random.randint(low,up),end='\\t')
  11.          
  12. def countdigit(n):
  13.      c=0
  14.      while n!=0:
  15.           c+=1
  16.           n//=10
  17.      print('the number of digits is',c)
  18. def calculator(a,op,b):
  19.      if op=='+':
  20.           s=a+b
  21.           print('Sum is',s)
  22.      elif op=='-':
  23.           d=a-b
  24.           print('Difference is',d)
  25.      elif op=='*':
  26.           m=a*b
  27.           print('Multiplication is',m)
  28.      elif op=='/':
  29.           s=a+b
  30.           print('Quotient is',qt)
  31. ch=1
  32. while ch!=4:
  33.     print("1.To input 2 integers and generate 1 random numbers")
  34.     print("2.To pass an integer argument and return the no: of digits.")
  35.     print("3.To pass 2 integer argument and operator to perform operations of a calculator.")
  36.     print("4. To Exit")
  37.     ch=int(input("Enter choice:"))
  38.     if ch==1:
  39.         low=int(input("Enter lower range"))
  40.         up=int(input("Enter upper range"))
  41.         generate()
  42.     elif ch==2:
  43.         n=int(input("Enter number"))
  44.         countdigit(n)
  45.     elif ch==3:
  46.         a=int(input("Enter First number"))
  47.         b=int(input("Enter Second number"))
  48.         op=input("Enter operator")
  49.         calculator(a,op,b)
  50.     elif ch!=4:
  51.         print("Invalid choice")
  52.     print("-"*20)
  53.  
  54.  
  55. ''' OUTPUT '''
  56. 1.To input 2 integers and generate 1 random numbers
  57. 2.To pass an integer argument and return the no: of digits.
  58. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  59. 4. To Exit
  60. Enter choice: 1
  61. Enter lower range 4
  62. Enter upper range 8
  63. 7 6 6 6 4 5 5 7 5 4 --------------------
  64. 1.To input 2 integers and generate 1 random numbers
  65. 2.To pass an integer argument and return the no: of digits.
  66. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  67. 4. To Exit
  68. Enter choice: 2
  69. Enter number 9945
  70. the number of digits is 4
  71. --------------------
  72. 1.To input 2 integers and generate 1 random numbers
  73. 2.To pass an integer argument and return the no: of digits.
  74. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  75. 4. To Exit
  76. Enter choice: 3
  77. Enter First number 5
  78. Enter Second number 5
  79. Enter operator +
  80. --------------------
  81. 1.To input 2 integers and generate 1 random numbers
  82. 2.To pass an integer argument and return the no: of digits.
  83. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  84. 4. To Exit
  85. Enter choice: 3
  86. Enter First number 6
  87. Enter Second number 9
  88. Enter operator*
  89. Multiplication is 54
  90. --------------------
  91. 1.To input 2 integers and generate 1 random numbers
  92. 2.To pass an integer argument and return the no: of digits.
  93. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  94. 4. To Exit
  95. Enter choice:3
  96. Enter First number 8
  97. Enter Second number4
  98. Enter operator-
  99. Difference is 4
  100. --------------------
  101. 1.To input 2 integers and generate 1 random numbers
  102. 2.To pass an integer argument and return the no: of digits.
  103. 3.To pass 2 integer argument and operator to perform operations of a calculator.
  104. 4. To Exit
  105. Enter choice:4
  106. --------------------