Post

100 Days Of Python - Day 1

Python - Day 1

Printing

1
print("Hello World")

Input

1
2
print("Hello " + input("What is your name? "))

String length

1
print(len(input("What is your name? ")))

Variables

To create a variable, you just have to give it a name and set it equal to a value.

1
2
name = "Jack"
print(name)

Variable naming rules

  • Variables names can not start with a number.
  • Variables can not contain spaces, use _ instead.
  • Variables can not contain any of these symbols:

    1
    
    `:'",<>/?|\!@#%^&*~-+`
    
  • It’s considered best practice (PEP8) that names are lowercase with underscores instead of spaces. For example:
  • snake_case instead of MACRO_CASE
  • CapitalizedWords or CamelCase instead of PascalCase
  • Avoid using special symbols like @, $, %, etc.
  • Don’t start a variable name with a digit.

Challenge

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Write a program that switches the values stored in the variables a and b.

# Warning. Do not change the code below. Your program should work for different inputs. e.g. any value of a and b.

# Example Input
a = input("a: ")
b = input("b: ")

# Example Output
# a: 3
# b: 5

# a: 5
# b: 3

####################################
# Don't change the code below πŸ‘‡

c = a
a = b
b = c

# Don't change the code above πŸ‘†

####################################
#Write your code below this line πŸ‘‡

print("a: " + a)
print("b: " + b)

Challenge

1
2
3
4
5
6
7
# Write a program that generates a band name based on the user's hometown and pet name.

print("Welcome to the Band Name Generator.")
city = input("What's name of the city you grew up in?\n")
pet = input("What's your pet's name?\n")
# Example Output
print("Your band name could be " + city + " " + pet)
This post is licensed under CC BY 4.0 by the author.