Advertisement
OreganoHauch

loop through dictionary?_3

Mar 30th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. print("Hier unten seht Ihr viermal die gleiche Ausgabe. Es gibt vier verschiedene Möglichkeiten, diese Ausgabe hinzukriegen.")
  2.  
  3. # Difficult?
  4.  
  5. string_dictionary = {
  6. 1: " +1. open+: +1",
  7. 2: " +2. high+: +1",
  8. 3: " +3. low+: +1",
  9. 4: " +4. close+: +1",
  10. 5: " +5. volume+: +5"
  11. }
  12.  
  13.  
  14. for i in range(1,6):
  15. print(len(string_dictionary[i]))
  16.  
  17. # More difficult? (Entries in a dictionary, string + integer variables.)
  18.  
  19. print("--------")
  20.  
  21. string_dictionary = {
  22. "x1": " +1. open+: +1",
  23. "x2": " +2. high+: +1",
  24. "x3": " +3. low+: +1",
  25. "x4": " +4. close+: +1",
  26. "x5": " +5. volume+: +5"
  27. }
  28.  
  29. for i in range(1,6):
  30. print(len(string_dictionary["x" + str(i)]))
  31.  
  32. print("--------")
  33.  
  34. string_dictionary = {
  35. "x1": " +1. open+: +1",
  36. "x2": " +2. high+: +1",
  37. "x3": " +3. low+: +1",
  38. "x4": " +4. close+: +1",
  39. "x5": " +5. volume+: +5"
  40. }
  41.  
  42. for key in string_dictionary:
  43. print(len(string_dictionary[key]))
  44.  
  45. print("--------")
  46.  
  47. # Insanely difficult? (Just the variables outside of a dictionary.)
  48.  
  49. x1 = " +1. open+: +1",
  50. x2 = " +2. high+: +1",
  51. x3 = " +3. low+: +1",
  52. x4 = " +4. close+: +1",
  53. x5 = " +5. volume+: +5"
  54.  
  55. for i in range(1,6):
  56. print(len(xi))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement