In: Computer Science
Using Python
Question 1
Write an input function. Then use it to supply the input to following additional functions:
i) Print multiplication table of the number from 1 to 12.
ii) Print the sum of all the numbers from 1 to up the number given.
iii) Print if the number supplied is odd or even.
Question 2
Write function that asks for input from a user. If the user types 'end', the program exits, otherwise it just keeps going.
def mul_table(number):
for i in range(1,13):
print(number,'x',i,'=',number*i)
def sum_of_num(number):
s=0
for i in range(1,number+1):
s=s+i
print("The sum of all the numbers from 1 to ",number," is : ",s)
def odd_even(number):
if number%2==0:
print("The number ",number," is : even")
else:
print("The number ",number," is :odd")
#input
number=int(input("enter number : "))
#Print multiplication table of the number from 1 to 12.
print("-----------------------multiplication table from 1 to 12 :-----------------------")
mul_table(number)
#ii) Print the sum of all the numbers from 1 to up the number given.
print("----------------------- Print the sum of all the numbers from 1 to up the number given:-----------------------")
sum_of_num(number)
#iii) Print if the number supplied is odd or even.
print("-----------------------checking whether the the number is odd or even-----------------------")
odd_even(number)
---------------------------------------------------------------------------------------------
Question 2:
import sys
#condition is always true
while(1):
input_user=input("Enter something,to exit enter end : ")
if(input_user=="end"):
#exit when user type end
sys.exit()
------------------------------------------------------------------------------------------------------------------------