razacodes

razacodes

❇️ Python Tech Trivia ❇️ Chapter 1

❇️ Python Tech Trivia ❇️ Chapter 1

Welcome to ❇️ Python Tech Trivia ❇️

These are some exercises I post on Twitter every day.

These exercises are meant for beginners to practice what you've learned.

After all, practice makes perfect!

Content

  • Exercises
  • Answers

Let's start :)

Exercise 1

x = 'nowgoandcodesomepython'

print(x[-6::].title())

Exercise 2

X = 12
Y = 4
Z = 3
print( X % Y * Z)

Exercise 3

year_born = 1890

current_year = 2021

age = current_year-year_born

print(f'I am {str(age)} years old!')

Exercise 4

year_born = 1890

current_year = 2021

age = current_year-year_born

name = 'Raza'

print(name + ' is ' + age + ' years old!')

Exercise 5

O = 'nowgoandcodesomepython'

print(len(o))

Answers

Did you do all the exercises first? You didn't cheat did you!?

Alright go ahead. Here are the answers

Exercise 1

x = 'nowgoandcodesomepython'

print(x[-6::].title())
>>> Python

Exercise 2

X = 12
Y = 4
Z = 3
print( X % Y * Z)
>>> 0

Exercise 3

year_born = 1890

current_year = 2021

age = current_year-year_born

print(f'I am {str(age)} years old!')
>>> I am 131 years old!

Exercise 4

year_born = 1890

current_year = 2021

age = current_year-year_born

name = 'Raza'

print(name + ' is ' + age + ' years old!')

>>> Error! 'age' needs to be converted to a string!

Exercise 5

O = 'nowgoandcodesomepython'

print(len(o))

>>> Error! Python is case sensitive. We defined 'O', not 'o' !
 
Share this