Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
10327 views
ubuntu2004
Kernel: Python 3 (system-wide)

Exercise 5.1

  1. Assign the string "The Beagle" to a string variable called darwin_ship.

  2. Print darwin_ship.

  3. Print the length of darwin_ship.

darwin_ship = "The Beagle" print(darwin_ship) print(len(darwin_ship))
The Beagle 10

Exercise 5.2

  1. Assign the empty string to the variable famous_scientists.

  2. Add "Jane" to your empty string.

  3. Add a space to your string.

  4. Add "Goodall" to your string and print it.

famous_scientists = "" famous_scientists = famous_scientists + "Jane" famous_scientists = famous_scientists + " " famous_scientists = famous_scientists + "Goodall" print(famous_scientists)
Jane Goodall

Exercise 5.3

  1. Ask for input of your name.

  2. Ask for input of your age.

  3. Using an f-string print

    X is Y years old

where X is your name and Y is your age.

x = input("input of your name") y = input("input of your age") print(f"{x} is {y} years old")
input of your name
input of your age
Artur is 18 years old

Exercise 5.4

  1. Ask for input of 2 decimal numbers.

  2. Using an f-string print

    X / Y = Z

where X and Y are the two numbers and Z is the result of X divided by Y rounded to 1dp.

x = input() y = input() print(f"{int(x)/int(y):.1}")
0.3

Exercise 5.5

  1. Assign the numbers 4.5735, 9.4253 and 1.223 to the variables x, y, and z respectively.

  2. Using an f-string print each number rounded to 2dp and separated by a tab.

x = 4.5735 y = 9.4253 z = 1.223 print(f"{x:.2}\t{y:.2}\t{z:.2}")
4.6 9.4 1.2