Instructions For each of the questions below, you are given a program expressed in simple pseudocode. (This is similar to the in-class exercises we did during Lecture 2.) From this pseudocode, you must implement a working program in Python.

computer science

Description

Home Work 1

Instructions For each of the questions below, you are given a program expressed in simple pseudocode.  (This is similar to the in-class exercises we did during Lecture 2.)  From this pseudocode, you must implement a working program in Python.  For this exercise, you will only need to use concepts we have discussed in class such as variables, expressions,​ input()​, casting to an integer or float, and​ print()​.

 The pseudocode may combine multiple lines of code into one step, or they may split something that would take a single line of code into multiple pieces. Think carefully about what the overall goal of the program is before you begin coding.

 At the end, your Homework 1 files must run without any errors.

Coding Standards Prior to this assignment, you should read the Coding Standards, linked on the course website at the top of the “Assignments” page.

 

For now, you should pay special attention to the sections about: ● Naming Conventions ● Use of Whitespace ● Comments (specifically, File Header Comments)

 

We will not grade “harshly” on Coding Standards this early in the semester, but you should start forming good habits now.  Make sure to pay attention to your TA’s feedback when you receive your Homework 1 grade back.

 Additional Specifications For this assignment, ​you must use​ if __name__ == '__main__':​ ​as seen in your​ lab2.py​ ​file, and as discussed in class.

 

For this assignment, you do ​not​ need to worry about any “input validation.”

 If the user enters a different type of data than what you asked for, your program may crash.  This is acceptable. If the user enters “bogus” data (for example: a negative value when asked for a positive number), this is acceptable.  (Your program does ​not​ need to worry about correcting the value or fixing it in any way.)

 

For example, if your program asks the user to enter a whole number, it is acceptable if your program crashes if they enter something else like “dog” or “twenty” or “88.2” instead.

 

Here is what that error might look like:

 Please enter a number: twenty Traceback (most recent call last):   File "test_file.py", line 10, in <module>     num = int(input("Please enter a number: ")) ValueError: invalid literal for int() with base 10: 'twenty'

 

Questions Each question is worth 6 points.  Following the directions is worth 4 points.

 

 

Question 2

Write your program for Question 2 in a file called ​hw1_part2.py​.

 This program, shown in pseudocode, asks for the user’s daily income and the cost of their favorite candy bar, and then calculates and prints out how many candy bars their daily income is worth.

 

Translate this pseudocode into a Python program.

 Ask the user how much money they make in a day Ask the user how much their favorite candy bar costs Calculate the number of candy bars they earned that day and print it

 For this program, the names of the variables are not given to you.  You should choose ​meaningful​ variable names.

 

 

Here is some sample output, with the user input in ​blue​.

 (Yours does not have to match this word for word, but it should be similar. The calculated costs should be the exact same, given the same input.)

 linux3[6]% python3 hw1_part2.py What is your daily income? ​50 How much does your favorite candy bar cost? ​1.2 You earned 41.66666666666667 candy bars today!

 linux3[7]% python3 hw1_part2.py What is your daily income? ​10 How much does your favorite candy bar cost? ​.8 You earned 12.5 candy bars today! 


Related Questions in computer science category