8b333f96f88f700474ed447abde95043 python lab2 v3 rasb14 2018-09-15 09:18:43 v3.1.2 (2018-09-06)
Generated 2018-09-15 11:18:43 by dbwebb lab-utility v3.1.2 (2018-09-06).
In this exercise we will look into flow-control. If-statements, for-loops and while-loops.
The basics of boolean operators and if-statements.
Create three variables representing dice values: dice1 = 1, dice2 = 4 and dice3 = 2.
Answer with the boolean value of the expression ‘dice1 is greater than dice2’.
Sum the three variables dice1, dice2 and dice3.
Use an if-statement to decide if the sum of the three variables i greater than 11. If the sum is greater than 11 answer with ‘big’ otherwise answer with ‘small’.
Add the sum of dice4 = 1 and dice5 = 3 to the sum of the three other dices.
Use an if, elseif, else statement to check the total value of the dices. Answer with ‘small’ if the sum is smaller than 11, ‘intermediate’ if the sum is greater than or equal to 11 but smaller than 21. If the sum is greater than or equal to 21 answer with ‘big’.
Create a variable summer_word containing the word ‘beach’.
Answer with True if summer_word contains the letter ‘s’ otherwise answer with False.
Tip: Use the in operator.
The basics of iteration and for-loops.
Loop through the numbers 0 to 10 (10 included) and concatenate a string with the numbers comma-separated. You should have a comma at the end of the string.
Answer with the string.
Loop through the letters of the variable summer_word from above. Concatenate the consonants from summer_word and answer with the new word.
Tip: Create a string that contains consonants and check if each letter is in it.
Loop through all numbers from 37 to 73 both numbers included. Add all odd (udda) numbers together and answer with the result.
Tip: Use the modulus % operator.
The basics of while-loops.
Create a while-loop that starts at value 6 and ends when the value is greater than 34, the value should be incremented by 3 for each iteration. Concatenate a string with the values comma-separated. You should have a comma at the end of the string.
Answer with the string.
Create a while-loop that adds 6 to the number 30, 34 times. Answer with the result.
Create a while-loop that subtracts 3 from 18, 40 times. Answer with the result.
These questions are worth 3 points each. Solve them for extra points.
Use a for-loop or a while-loop to reverse the word ‘disproportionality’.
Answer with the reversed word.
Swedish numberplates consist of three letters and three numbers. The numbers range from 001 to 999. Using one of the four common rules of arithmetics (+, -, *, /), on how many of the numberplates can the two first numbers give the third number?
Examples: ‘ABC123’ can be combined to 1 + 2 = 3. So this numberplate is good. ‘ABC129’ 1 and 2 cannot be combined to give 9 using the four rules of arithmetics, so this does not work.
Order matters, so only use 1 +-/ 2 = 3 and not 2 +-/ 1 = 3.
Do not count multiple times if more than one rule of arithmetics work.
Answer with the number of numberplates.
8b333f96f88f700474ed447abde95043