Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # gunn class dec-26-2020
- ## key ideas
- - programs run from top to bottom
- - everything after # in that line will not be used in computation. this is called a "comment." useful for annotating the code / storing unused code.
- - leftside = rightside means evaluate the right side first, then save the final value in the variable named leftside
- - print(any variable or literal)
- - input() "returns" whatever we receive from the user as a string (since we want to use the value later, we need to save it in a variable. e.g. x = input().)
- ## homework
- create separate repl files for problem 2, 3, and 4. (just creating a new file in the repl file we used in class won't work. you'll need a completely separate workspace.) good luck on the homework!
- ### problem 1
- do some investigative work (aka guess or google) to figure out which of these variable names are allowed and not allowed. report your finding in class.
- customerName
- ID
- address1
- %available
- auto
- Int
- 3rdSubject
- _sys_one
- address_2
- number5
- #5
- ### problem 2
- write a program that receives temperature in celsius from the user then outputs that temperature in farenheit
- hint:
- - recall that temperature might not just be an integer. what data type should you use?
- - you can't just use the mathematical formula (F-32)/9 = C/5 directly. this is programming. you need to use = as a way to assign value from right side to left side. (how?)
- ### problem 3
- write a program that receives 3 values. manipulate the values so you have the ordering: second, third, first.
- for example, if the input is 3, 7, 10. the output should be 7, 10, 3.
- (this is supposed to be an extension of the swap program we wrote in class. don't just swap the variables in print commands. actually somehow change the values of the variables.)
- ### problem 4
- write a program that receives two numbers, called a and b. then compute a+(a+1)+(a+2)+...+b.
- for example if input is 1 and 10, the output should be 55 (because 1+2+3+...+10 = 55).
- hint:
- - you haven't learned about loops yet, but you definitely learned about arithmetic series in school. use your math knowledge.
- ### extra challenge problem
- write a program that receives a number (amount of money in thai baht). output the minimum number of banknotes+coins require to make that amount. for example 4823 = 1000+1000+1000+1000 + 500 + 100+100+100 + 20 + 2 + 1. so, output 11 (there are 8 banknotes plus 3 coins).
- you will find these operators useful: suppose a and b are int.
- a + b obvious
- a - b obvious
- a * b obvious
- a // b is a divided by b but without the decimal part (e.g. 13 // 4 is 3)
- a % b is the remainder of dividing a by b (e.g. 13 % 4 is 1)
- hint:
- - first try to calculate the number of 1000 notes required. calculuate how much money is left. then continue with other banknote type.
Add Comment
Please, Sign In to add comment