In: Computer Science
What to do:
1. Write a Python program, a1.py with the following
characteristics:
a) there are at least 40 lines of comments and 40 lines of code (1
point)
b) the problem is described at the top of the program in a readable
fashion (1 point)
c) the code includes at least one instance of each of the five
learning objectives listed above. (3 points) d) the code solves the
problem. This may be assessed in part by a 'code walkthrough' where
you explain
your code to the TA. (4 points)
2. Run your program and collect the output in a text file called
output.txt (1 point)
II have to make my own question and solve it through by making a program. This is my assignment but i haven't covered the chapters of my course yet and hence i don't have the knowledge to do this assignment within a short span of time. It can be any simple program but all the requirements should be met given above. Also please note, 20 comments will also work instead of 40 but 20 comments is a must for the program describing what the program is about. The chapters which were covered before this assignment was given were the following: 1) Introduction through python 2) Some simple numerical problems 3) Functions, Scoping and Abstractions from the book Introduction to Computation and Programming Using Python by John V. Guttag.
Please note, the program shouldn't be copied from anywhere and should be unique.
Please find the attached code below. I have written COMMENTS and SAMPLE OUTPUT in the code for better and easy understanding of the answer.THANK YOU !
''' ------------------- PROBLEM STATEMENT --------------------------
This is a python program which takes two integer inputs from the user and
then tells the user whether the numbers are positive or negative integers.
Then this program compares the two numbers and tells which is the larger number
out of the two given numbers. Then this program performs all the basic arithmetic
operations on the two numbers like addition, subtraction , multiplication, division,
floor division, exponent of num1 to num2 and modulus.Now the program prints all the
calculated values on the console for the user. '''
# Store input numbers:
num1 = input('Enter first number:') #reading the num1
print("\n")
num2 = input('Enter second number:') #reading the num2
print("\n")
# Adding two numbers
sum = float(num1) + float(num2)
# Subtracting two numbers
min = float(num1) - float(num2)
# Multiplying two numbers
mul = float(num1) * float(num2)
#Dividing two numbers
div = float(num1) / float(num2)
#floor division of 2 numbers
floor_div = num1 // num2
#exponent of num1 to the power of num2
power = num1 ** num2
#modulus operation
modulus=num1%num2
if num1>0 : #if num1 is positive
print("First number is a positive integer")
else : # if num1 is negative
print("First number is a negative integer")
if num2>0 : #if num2 is positive
print("Second number is a positive integer")
else : #if num2 is negative
print("Second number is a negative integer")
if num1>num2 : # if num1 is larger display the message
print("First number is greater than the second")
else : # if num2 is larger we display the message below
print("First number is smaller than the second")
# Display the sum
print('The sum of {0} and {1} is {2}'.format(num1, num2, sum))
# Display the subtraction
print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min))
# Display the multiplication
print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul))
# Display the division
print('The division of {0} and {1} is {2}'.format(num1, num2, div))
# Display the floor division
print('The floor division of {0} and {1} is {2}'.format(num1, num2,floor_div))
# Display the power
print('The power of {0} raised to {1} is {2}'.format(num1, num2, power))
# Display the modulus
print('The modulus of {0} and {1} is {2}'.format(num1, num2, modulus))
''' ------------------SAMPLE OUTPUT --------------------------------------------------------------
SAMPLE OUTPUT 1 ( WHEN NUM1 IS POSITIVE AND NUM2 IS NEGATIVE)-->
Enter first number:
5
Enter second number:
-6
First number is a positive integer
Second number is a negative integer
First number is greater than the second
The sum of 5 and -6 is -1.0
The subtraction of 5 and -6 is 11.0
The multiplication of 5 and -6 is -30.0
The division of 5 and -6 is -0.833333333333
The floor division of 5 and -6 is -1
The power of 5 raised to -6 is 6.4e-05
The modulus of 5 and -6 is -1
SAMPLE OUTPUT 2 (WHEN BOTH ARE POSITIVE)-->
Enter first number:
10
Enter second number:
6
First number is a positive integer
Second number is a positive integer
First number is greater than the second
The sum of 10 and 6 is 16.0
The subtraction of 10 and 6 is 4.0
The multiplication of 10 and 6 is 60.0
The division of 10 and 6 is 1.66666666667
The floor division of 10 and 6 is 1
The power of 10 raised to 6 is 1000000
The modulus of 10 and 6 is 4
SAMPLE OUTPUT 3 (WHEN BOTH ARE NEGATIVE)-->
Enter first number:
-7
Enter second number:
-4
First number is a negative integer
Second number is a negative integer
First number is smaller than the second
The sum of -7 and -4 is -11.0
The subtraction of -7 and -4 is -3.0
The multiplication of -7 and -4 is 28.0
The division of -7 and -4 is 1.75
The floor division of -7 and -4 is 1
The power of -7 raised to -4 is 0.000416493127863
The modulus of -7 and -4 is -3
-----------------------------------------------------------------------------------------------'''
THANK YOU !