ae2bf93b291eb813fd712f6be4eaff7d
python
lab1
v3
rasb14
2018-09-08 10:33:52
v3.1.2 (2018-09-06)

Generated 2018-09-08 12:33:52 by dbwebb lab-utility v3.1.2 (2018-09-06).


Lab 1 - python

If you need to peek at examples or just want to know more, take a look at the Python manual.

There you will find everything this lab will go through and much more.

1. Integers, floats and basic arithmetics

The foundation of numbers and basic arithmetic.

Exercise 1.1 (1 points)

Create a variable called num_one and give it the value 41.

Answer with the value of num_one.

Exercise 1.2 (1 points)

Create another variable called num_two and give it the value 87. Create a third variable called result and assign to it the sum of the first two variables.

Answer with the result variable.

Exercise 1.3 (1 points)

Create a variable called num_three and give it the value 15.

Create another variable called num_four and give it the value 33.

Subtract num_three from num_four and add the result variable from above to result of the subtraction. Answer with the result.

Exercise 1.4 (1 points)

Answer with the result of a multiplication of num_one and num_three.

Exercise 1.5 (1 points)

Create a variable called float_one and give it the value 56.13.

Create another variable called float_two and give it the value 33.16.

Sum the two values and answer with the result, rounded to two decimals. Use the function round() to round the number to two decimals.

Exercise 1.6 (1 points)

All variables used in the exercise below are defined above.

Sum num_three with num_one and subtract num_four. Multiply the result by num_two, add float_two and subtract float_one. Use the function round() to round the number to two decimals.

Answer with the result.

2. Strings and concatenation

Exercise 2.1 (1 points)

Concatenate (svenska: konkatenera) the two words ‘storage’ and ‘icecream’ and answer with the result.

Exercise 2.2 (1 points)

Concatenate the word ‘icecream’ with the integer 41, with a space between the two values. Answer with the new string.

Exercise 2.3 (1 points)

Concatenate the integer 41 with the word ‘storage’ with a space between. To the resulting string concatenate the string ’ and ‘. To this string concatenate integer 87 and the word ‘icecream’ with a space between between the two variables.

Exercise 2.4 (1 points)

Assign the string value ‘30’ to a variable called string_number and assign the integer value 5 to a variable called actual_number.

Use int() to change the type of string_number to an integer and divide the integer value with actual_number. Answer with an integer by using the function round().

3. Extra assignments

These questions are worth 3 points each. Solve them for extra points.

Exercise 3.1 (3 points)

BTH have two plugin-hybrid cars. A new car and an old car. The new car has a fast charging mode where 80% of the battery can be charged in 30 minutes. The remaining 20% of the battery and the entire battery of the old car is charged by 5% every 30 minutes.

During fast charging the effect of the charger is 200W and during normal charging the effect of the charger is 100W.

The formula for calculating the amount of energy based on effect and time is: energy = effect * time. To get the amount of energy in kWh the formula is energy = (effect in W * time in hours) / 1000.

Calculate the total amount of energy used to fully charge the two cars. Answer with the amount of energy in kWh.

Exercise 3.2 (3 points)

Peter has the phonenumber ‘0731415926’ and Anna has the phonenumber ‘0727182818’. They call each other every sunday afternoon for 9 minutes.

Calculate the number of hours that they talk with each other pr year (assume 52 sundays pr year). Use that number in a string concatenation with the following format:

‘Peter calls from [#Peter’s phonenumber] to Anna on [#Anna’s phonenumber] for [#hours] hours every year.’

Replace the content inside [#] with the corresponding values.

Answer with the concatenated string.


ae2bf93b291eb813fd712f6be4eaff7d