The assignment will be graded out of 100 points. Create a text document entitled answers.xxx (where you replace xxx with whatever extension is appropriate, depending on the file format you use). Acceptable file formats are plain text, Word document, OpenOffice document, and PDF. Put your name and UTA ID in the file on the first line. Your answers that are not part of a program will be added to this file. Each task below will instruct you where to put your answers.
myVar1 = 7.0 myVar2 = 5 print(myVar1 % myVar2)
If you execute these three lines of code, what will be printed? Put your answer in the answers.xxx file.
What will be printed by the following code?
x = 4 y = 5 print(x/y)
Put your answer in your answers.xxx file.
Which lines of the following code are statements and which are expressions? Assume the lines of code are run in order. Put your answers in answers.xxx
a = int(2.0) # line 1 float(2) # line 2 a ** 7 # line 3 print("a =", a) # line 4 a *= 2 # line 5
square_area = side_length ** 2 side_length = 10 print(square_area)
The above code is an incorrect attempt to compute that, if the length of the side of a square is 10, then the circumference of the square is 10 squared, which is 100.
If you try to run the above code, it will not work. Rewrite the program so that it works, and save it as task4.py. You may have to experiment with it to determine what is wrong if the Python error message does not give you enough information.
Also, in your answers.xxx file, explain exactly (only a few words are needed) why the code, as given above, does not work.
cost_string = '32,000' quantity_string = '10' total_cost = int(cost_string) * int(quantity_string) print(total_cost)
The above code is an incorrect attempt to compute that, if each item costs $32,000, and we produce 10 items, then the total cost is $320,000 (which is $32,000 times 10).
If you try to run the above code, it will not work. Rewrite the program so that it works, and save it as task5.py. You may have to experiment with it to determine what is wrong if the Python error message does not give you enough information.
Also, in your answers.xxx file, explain exactly (only a few words are needed) why the code, as given above, does not work.
# This program calculates the area of a triangle base = input("Enter the triangle base: ") height = input("Enter the triangle height: ") area = (base * height) / 2 print("Area =", area)Write a corrected version of the above program and save it as task6.py.
One way to determine whether an integer is even is to divide the number by two and check the remainder. If the remainder is one, the number is odd; if the remainder is zero, the number is even. Write a program that prompts the user for a number, converts the number to an integer, and prints "even" if the number is even and prints "odd" if the number is odd. Save your program as task7.py.
The area A of a rectangle can be calculated by multiplying the length and the width: A = l × w. The perimeter of a rectangle can be calculated with P = 2(l + w). Write a program that prompt the user for the length and width of a rectangle and outputs the area and perimeter. Save your program as task8.py.
A day has 86,400 secs (24 hrs * 60 mins * 60 secs). Write a program that prompts the user for a number seconds in the range 1 to 86,400 and output the time as hours, minutes, and seconds with a 24-hour clock. If the user inputs something that is not an integer, you do not have to worry about it (just let the program crash). If the user inputs an integer that is less than 1 or greater than 86,400, you should also not worry about it (do not do anything to handle that case in any special way).
You can divide the user's value by 3600 (the
number of seconds in an hour) to determine the number of hours and divide the remainder
of that operation by 60 (the number of seconds in a minute) to calculate the
number of minutes. The remainder of that operation will be the number of seconds.
To illustrate:
The assignment should be submitted via Blackboard. Submit a ZIPPED directory called assignment1.zip (no other forms of compression accepted, contact the instructor or TA if you do not know how to produce .zip files). The zipped directory should contain your answers.xxx document and all the Python code files (task5.py, task6.py, etc).