Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IDLE
- # Exercise 1
- # Create variables which will store data like your name (text), age (number), favourite meal (text) or favourite meal (text).
- # Display the text using the print() function. Use the created variables
- # Example:
- # My name is Adam, I’m 15 years old, my favourite meal is pizza and my favourite game is Minecraft.
- # Remember to convert the number to text (use str()). Use the + symbol to connect text to variables.
- ime = 'Marijan'
- godine = 35
- jelo = 'pizza'
- igra = 'Minecraft'
- print('My name is ' + ime + '. I’m ' + str(godine) +' years old, my favourite meal is ' + jelo + ' and my favourite game is ' + igra)
- # Exercise 2
- # Write a script which will let the user enter grades from three subjects and display their average.
- # To get data from the user, use the input() function.
- # Remember that this function gets data as text and we need numbers to count the average
- # Our grade should be 5 and not "5" because 5+5=10, and "5"+"5"="55". Use int() function.
- # for example. int(input("enter your English grade: "))
- # You can count an average by adding all the grades together and dividing the sum by their amount (the symbol of division is /).
- matematika = int(input("Upisi ocjenu iz matematike:"))
- hrvatski = int(input("Upisi ocjenu iz hrvatskog:"))
- engleski = int(input("Upisi ocjenu iz engleskog:"))
- zbroj_ocjena = matematika + hrvatski + engleski
- prosjek = zbroj_ocjena/3
- print(prosjek)
- # Exercise 3
- # Translator - create a program which will translate 5 different words in your language to English.
- # The user enters the words in their language and gets an answer:
- # >> Enter a word to translate: przycisk
- # Przycisk in English: button
- # For unknown words the following message should appear:
- # “Unfortunately, we do not have translation data for this word in our database yet.”
- # Use the if elif else conditional statements.
- # Use a while True loop so the program repeats itself all the time.
- # Remember about indentation (tab button).
- while True:
- word_to_translate = input("Enter a word to translate")
- if word_to_translate == 'petlja':
- print(word_to_translate + " in English is: loop")
- elif word_to_translate == 'gumb':
- print(word_to_translate + " in English is: button")
- elif word_to_translate == 'varijabla':
- print(word_to_translate + " in English is: variable")
- elif word_to_translate == 'rezultat':
- print(word_to_translate + " in English is: score")
- elif word_to_translate == 'knjiga':
- print(word_to_translate + " in English is: book")
- else:
- print("Unfortunately, we do not have translation data for this word in our database yet")
- # Exercise 4
- # Create a loop which will display numbers from -10 to 100.
- # Use the range() function.
- for i in range(-10,101):
- print(i)
- # Exercise 5*
- # Create an array named numbersArray and save 5 numbers in it.
- # Using a loop, get each element of the table and display the squared value of it.
- # Example:
- # For the number 2 the following should be displayed: 2 squared is 4
- # For the number 5: 5 squared is 25
- # Use the len() function which returns the length of the array.
- # Use a for loop to get all the elements from the array.
- numbersArray = [25, 13, 11, 2, 5, 4, 17]
- for i in range(len(numbersArray)):
- print(str(numbersArray[i]*numbersArray[i]))
- for number in numbersArray:
- print(number*number)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement