Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. # Python Starter Quiz
  2. # Try your best to answer these questions. It’s just an assessment so I can get
  3. # a feel for the level of Python skills in the class. No stress and no grade for this :)
  4.  
  5. # Question 1 :
  6. # Print out “Coding is awesome :)”
  7.  
  8. print "Coding is awesome :)"
  9.  
  10. # Question 2:
  11. # Print the first 50 even numbers greater than 900
  12.  
  13. nums = []
  14. i = 901
  15. while len(nums) < 50:
  16. if i % 2 == 0:
  17. nums.append(i)
  18. i += 1
  19. for num in nums:
  20. print num
  21.  
  22. # Question 3:
  23. # Print “The number you have inputted plus 5 is: <their number + 5>”.
  24. # We’ve given you code to read in the number
  25.  
  26. mynumber = float(raw_input("Please enter a number:"))
  27.  
  28. print "The number you have inputted is : " + str(mynumber+5)
  29. # Question 4:
  30. # print a list of 1000 1’s : [1,1,1,1,1,1] …
  31. print [1]*1000
  32.  
  33. # Question 5:
  34. # Make a function that given two lists returns the combined list.
  35. # e.g : merge([1,2,3], [4,5,6]) … would give you [1,2,3,4,5,6]
  36.  
  37. def merge(a, b):
  38. return a + b
  39. print([1,2,3], [4,5,6])
  40.  
  41. # Question 6:
  42. # Make a function that takes in dictionary and a value, if that value is in the dictionary
  43. # it returns the keys corresponding to the value
  44. # e.g : my_dict = { “A”: 7, “B”: 3 , “C”: 7} … find(my_dict, 7) would yield [“A”, “C”]
  45.  
  46. def find(my_dict, value):
  47. ret = []
  48. for key in my_dict:
  49. if my_dict[key] == value:
  50. ret.append(key)
  51. return ret
  52.  
  53. print find({ "A": 7, "B": 3 , "C": 7}, 7)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement