Question

In: Computer Science

What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...

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.

Solutions

Expert Solution

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 !


Related Solutions

What to do: 1. Write a Python program, a1.py with the following characteristics: a) there are...
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...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...
Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it. Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0. print("Enter n") n = int(input()) min = n while n != 0: if n < min:...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a...
Write a Python program (with comments) to do the following: Assign the value '2+1' to a variable str1. Use the eval() function to evaluate str1and assign the result to a variable num1. Ask the user to input their birth month and assign it to a variable month and then print it with a suitable message. Determine the number of letters in month and display the result with a suitable message. Determine how many times the letter 'r ' occurs in...
IN PYTHON Write a program to do the following: Solve the a set of equations as...
IN PYTHON Write a program to do the following: Solve the a set of equations as mentioned in "Zybook 5.20 LAB: Brute force equation solver". Instead of the arithmetic operators use your own function defined in a module named calc. You must provide two files (calc.py, brute_force_solver.py) :- 1) calc.py:- Add function named 'add' instead of using operator '+' [10pts] Add function named 'difference' instead of using operator '-' [10pts] Add function named 'product' instead of using operator '*' [10pts]...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
By only importing multiprocessing Write a python program which do the following : 1- Create one...
By only importing multiprocessing Write a python program which do the following : 1- Create one process this process must-read the content of a file “read any file content exist in your machine” and after that create another process in the first process function which will get the file content as a parameter for the second process function. 2- The second process function will get the file content and check out if there are any special characters or numbers in...
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
write an algorithm program using python or C++ where a0=1, a1=2 an=an-1*an-2, find an ,also a5=?
***This program is to be created using Python*** Requirements to be numbered in program01.py: Print “This...
***This program is to be created using Python*** Requirements to be numbered in program01.py: Print “This program provides concert seat assignments.” Ask the user their musical preference and take the following actions based on their potential input: Classical – proceed with the program (i.e. move the next requirement) – output a message that states “We do not recognize the musical genre.” Then end the program. Ask the user to enter the following data about themselves: • First Name • Last...
write a python program to do the following: ask a student for 3 coefficients a b...
write a python program to do the following: ask a student for 3 coefficients a b c using the high_school_quizz to display the solutions of a quadratic problem. after, ask the student if he would like another quadratic equation solved If the student answers anything but yes, the program terminates by displaying a good bye message if the student answers yes (any form of yes should be acceptable) , the student is asked for the coefficient again and the resulting...
Who knows to do this topic with python code? Write a program to perform the following...
Who knows to do this topic with python code? Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT