AquaBlitz11

gunn class dec-26-2020

Dec 26th, 2020 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. # gunn class dec-26-2020
  2.  
  3. ## key ideas
  4. - programs run from top to bottom
  5. - everything after # in that line will not be used in computation. this is called a "comment." useful for annotating the code / storing unused code.
  6. - leftside = rightside means evaluate the right side first, then save the final value in the variable named leftside
  7. - print(any variable or literal)
  8. - 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().)
  9.  
  10. ## homework
  11. 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!
  12.  
  13. ### problem 1
  14. 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.
  15. customerName
  16. ID
  17. address1
  18. %available
  19. auto
  20. Int
  21. 3rdSubject
  22. _sys_one
  23. address_2
  24. number5
  25. #5
  26.  
  27. ### problem 2
  28. write a program that receives temperature in celsius from the user then outputs that temperature in farenheit
  29. hint:
  30. - recall that temperature might not just be an integer. what data type should you use?
  31. - 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?)
  32.  
  33. ### problem 3
  34. write a program that receives 3 values. manipulate the values so you have the ordering: second, third, first.
  35. for example, if the input is 3, 7, 10. the output should be 7, 10, 3.
  36. (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.)
  37.  
  38. ### problem 4
  39. write a program that receives two numbers, called a and b. then compute a+(a+1)+(a+2)+...+b.
  40. for example if input is 1 and 10, the output should be 55 (because 1+2+3+...+10 = 55).
  41. hint:
  42. - you haven't learned about loops yet, but you definitely learned about arithmetic series in school. use your math knowledge.
  43.  
  44. ### extra challenge problem
  45. 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).
  46. you will find these operators useful: suppose a and b are int.
  47. a + b obvious
  48. a - b obvious
  49. a * b obvious
  50. a // b is a divided by b but without the decimal part (e.g. 13 // 4 is 3)
  51. a % b is the remainder of dividing a by b (e.g. 13 % 4 is 1)
  52. hint:
  53. - 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