Advertisement
mralasic

solutions

Jun 11th, 2022
918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.40 KB | None | 0 0
  1. # IDLE
  2.  
  3. # Exercise 1
  4. # Create variables which will store data like your name (text), age (number), favourite meal (text) or favourite meal (text).
  5. # Display the text using the print() function. Use the created variables
  6. # Example:
  7. # My name is Adam, I’m 15 years old, my favourite meal is pizza and my favourite game is Minecraft.
  8. # Remember to convert the number to text (use str()). Use the + symbol to connect text to variables.
  9.  
  10. ime = 'Marijan'
  11. godine = 35
  12. jelo = 'pizza'
  13. igra = 'Minecraft'
  14.  
  15. print('My name is ' + ime + '. I’m ' + str(godine) +' years old, my favourite meal is ' + jelo + ' and my favourite game is ' + igra)
  16.  
  17. # Exercise 2
  18. # Write a script which will let the user enter grades from three subjects and display their average.
  19. # To get data from the user, use the input() function.
  20. # Remember that this function gets data as text and we need numbers to count the average
  21. # Our grade should be 5 and not "5" because 5+5=10, and "5"+"5"="55". Use int() function.
  22. # for example. int(input("enter your English grade: "))
  23. # You can count an average by adding all the grades together and dividing the sum by their amount (the symbol of division is /).
  24.  
  25. matematika = int(input("Upisi ocjenu iz matematike:"))
  26. hrvatski = int(input("Upisi ocjenu iz hrvatskog:"))
  27. engleski = int(input("Upisi ocjenu iz engleskog:"))
  28.  
  29. zbroj_ocjena = matematika + hrvatski + engleski
  30.  
  31. prosjek = zbroj_ocjena/3
  32. print(prosjek)
  33.  
  34.  
  35.  
  36. # Exercise 3
  37. # Translator - create a program which will translate 5 different words in your language to English.
  38. # The user enters the words in their language and gets an answer:
  39.  
  40. # >> Enter a word to translate: przycisk
  41. # Przycisk in English: button
  42.  
  43. # For unknown words the following message should appear:
  44. # “Unfortunately, we do not have translation data for this word in our database yet.”
  45. # Use the if elif else conditional statements.
  46. # Use a while True loop so the program repeats itself all the time.
  47. # Remember about indentation (tab button).
  48.  
  49. while True:
  50.     word_to_translate = input("Enter a word to translate")
  51.    
  52.     if word_to_translate == 'petlja':
  53.         print(word_to_translate + " in English is: loop")
  54.     elif word_to_translate == 'gumb':
  55.         print(word_to_translate + " in English is: button")
  56.     elif word_to_translate == 'varijabla':
  57.         print(word_to_translate + " in English is: variable")
  58.     elif word_to_translate == 'rezultat':
  59.         print(word_to_translate + " in English is: score")
  60.     elif word_to_translate == 'knjiga':
  61.         print(word_to_translate + " in English is: book")
  62.     else:
  63.         print("Unfortunately, we do not have translation data for this word in our database yet")
  64.  
  65.  
  66. # Exercise 4
  67. # Create a loop which will display numbers from -10 to 100.
  68. # Use the range() function.
  69. for i in range(-10,101):
  70.     print(i)
  71.  
  72.  
  73. # Exercise 5*
  74. # Create an array named numbersArray and save 5 numbers in it.
  75. # Using a loop, get each element of the table and display the squared value of it.
  76. # Example:
  77. # For the number 2 the following should be displayed: 2 squared is 4
  78. # For the number 5: 5 squared is 25
  79. # Use the len() function which returns the length of the array.
  80. # Use a for loop to get all the elements from the array.
  81. numbersArray = [25, 13, 11, 2, 5, 4, 17]
  82.  
  83. for i in range(len(numbersArray)):
  84.     print(str(numbersArray[i]*numbersArray[i]))
  85.    
  86. for number in numbersArray:
  87.     print(number*number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement