6 questions, short homework assignment need completed by 11pm pst today march 1
DSCI 510 Spring 2021 Homework #1 (100 points. Actually 101 if you look carefully…) DUE Monday, March 1, 2021, at 11:59PM, submitted via the course website. The first thing to note, is that this assignment is to be turned in via Python script files and text files, not Jupyter notebooks. That doesn’t mean you can’t do whatever development and debugging you’d like in a notebook, but your final submission deliverable is a zip file to be called [YOUR FIRSTNAME]_ [YOUR LASTNAME]_homework1.zip. (So for me, I would turn in a file called Yigal_ Arens_homework1.zip.) This zip file should contain 6 files, named · firstname_lastname_1.py (for me, Yigal_Arens_1.py), · firstname_lastname_2.py (for me, Yigal_Arens_2.py), · and so on. You may lose points if you do not follow the submission procedure. Question 1 (12 points) Assuming you typed the following in your Python interpreter: two = 2 ten = 10 zero = 1 tenplustwo = "ten" + "two" What is the output of the following: a) print(ten + two) b) print(ten + 1) c) print (two - 1 * zero - 0 + 10 ** ten) d) if zero - 1: print('ten') e) print(int(two) * 10 % 1 / int(ten) + 1 ** 10) f) print('tenplustwo' + tenplustwo + 'ten' + two) Question 2 (14 points) Fill in the following blanks, one per line: a) Python is a ________ typed language b) Values from the input() function in Python are returned as ________ c) The value of: 9 > 6 or abracadabra is ________. d) Why? ________________ e) The value of: 9 > 6 and abracadabra is ________. f) Why? ________________ g) Which function tells you the type of a Python object? _________ Question 3 (10 points) You are to design a guessing test that generates a random integer number between 1 and 10 and repeatedly prompts the user for a guess, at each time indicates if the guess is lower or higher than the randomly generated number. When the user guesses correctly, the program should terminate and indicate the number of tries the user took to guess the number correctly. Write out in how you would solve this problem. You can use full English sentences, pseudo-code, or diagrams if you like. The point is to work through how to design the logic you need to implement the above problem. Some example of pseudocode are here: https://www.unf.edu/~broggio/cop2221/2221pseu.htm Question 4 (25 points) Write a Python program that implements the logic you wrote in question 3. You will need to use the ‘randint’ function of the random package in Python. To do this include the following line at the beginning of your program: from random import randint After that, calling the function randint(m,n) with integer m and n will return a random integer between the numbers m and n. For example, randint(1,15) might return 12 or 1. Question 5 (10 points) Much like question 3, write out logic/pseudocode/diagrams for the following problem: You want to obtain input from the user in the form of a number of inches. The logic should then print the number of miles, yards, feet and/or inches equal to the value passed in. You should only print the minimum number of items; in other words, you should compute miles first, then yards, then feet, then inches. Here are some examples. Note that units that are zero are not printed out: If the user enters: 10 The program prints: You entered 10 inches If the user enters: 12 The program prints: You entered 1 foot If the user enters: 12 The program prints: You entered 1 foot 2 inches If the user enters: 49 The program prints: You entered 1 yard 1 foot 1 inch If the user enters: 63398 The program prints: You entered: 1 mile 1 yard 2 inches Question 6 (30 points) Write a program that Implements your logic from question 5 in Python. *** NOTE: We have a corpus of common solutions to these problems (from google, stackoverflow, previous semesters, etc.) If your solution is too similar/the same as other solutions (i.e. if you cheat), you will get a zero for this assignment and be subject to potential sanction from SJA. Please don’t.