In: Computer Science
Q.1: create a python function that takes two integers from the user ( pass them from the main program). The function performs the addition operation and returns the result. In the program, ask the user to guess the result. Then, the program compares the user input ( guess) with the returned value, and displays a message that tells if the user guessing is correct or not.
--define the function here ---
# the program starts here
print(“ This program tests your knowledge of the addition operation:”)
number1, number2 =input (“ Enter two numbers: “). ????? # complete the input statement by replacing #????
theNumber1 =int(number1)
theNumber2 =int(number2)
guess = float(input(“Enter your guess of adding the two numbers: “))
---call the function---
---- compare here-----
---- display the message-----
create a python function (only) that generates 10 random numbers within a specific range. Every time a number is generated, it is appended to a list (you need to initialize a list). Then the function counts how many times a number is repeated in the created list (you can choose any number to count). The function returns the list, the number you have chosen and its count.
--define the function here ---
Call the following function twice by passing a tuple of int and tuple of float:
def average(*args):
return sum(args) / len(args)
Code and output
Code fot copying
def addition(theNumber1,theNumber2):
c=theNumber1+theNumber2
return c
print("This program tests your knowledge of the addition
operation")
number1, number2 =input ("Enter two numbers: ").split(' ')
theNumber1 =int(number1)
theNumber2 =int(number2)
guess = float(input("Enter your guess of adding the two numbers:
"))
print("The addition of two numbers is
{}".format(addition(theNumber1,theNumber2)))
if addition(theNumber1,theNumber2)==guess:
print("Your guess is correct")
if addition(theNumber1,theNumber2)!=guess:
print("Your guess is not correct")
Code snippet
def addition(theNumber1,theNumber2):
c=theNumber1+theNumber2
return c
print("This program tests your knowledge of the addition operation")
number1, number2 =input ("Enter two numbers: ").split(' ')
theNumber1 =int(number1)
theNumber2 =int(number2)
guess = float(input("Enter your guess of adding the two numbers: "))
print("The addition of two numbers is {}".format(addition(theNumber1,theNumber2)))
if addition(theNumber1,theNumber2)==guess:
print("Your guess is correct")
if addition(theNumber1,theNumber2)!=guess:
print("Your guess is not correct")