8000 Working with Python data types · SeyiObe/intro-to-python@4a8ef34 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 4a8ef34

Browse files
author
Replit user
committed
Working with Python data types
1 parent 9c1dec6 commit 4a8ef34

File tree

2 files changed

+52
-3
lines changed

2 files changed

+52
-3
lines changed

session_02/answers/A14.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# A14 - Slice the string with steps of 2, excluding the first and last characters of the string "WelcometoPython"
22

3-
4-
# creating a variable with the string in
3+
# creating a variable with the string in
54
str = "WelcometoPython"
65

7-
# finding out the length of the string to decide which characters to exclude
6+
# finding out the length of the string to decide which characters to exclude
87
print(len(str))
98

109
# slicing the string with steps of 2, excluding the first and last character

session_02/lesson_2.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
width = 4
2+
height = 3
3+
area = width*height
4+
print("Rectangle of width " + str(width) + " and height " + str(height) + " has an area of " + str(area))
5+
6+
string = "python"
7+
print(len(string))
8+
9+
print(string[0])
10+
print(string[2])
11+
12+
name = input("What's your name? ")
13+
print("Hello " + name)
14+
15+
age = int(input("How old are you? "))
16+
adjusted_age = age + 15
17+
print("In 15 years, you will be " + str(adjusted_age))
18+
19+
print("Hello "+ name + ", you are currently " + str(age) + " years old. In 15 years time you will be " + str(adjusted_age) + ".")
20+
21+
hometown = input("What's your hometown? ")
22+
print(hometown.upper())
23+
24+
fav_color = input("What's your favourite color? ")
25+
print(len(fav_color))
26+
27+
month = input("What month is it? ")
28+
weather = input("How hot is it today? ")
29+
print("It is " + month + " and it is " + weather + "C today")
30+
31+
temp1 = int(input("What's the weather on Monday? "))
32+
temp2 = int(input("What's the weather on Tuesday? "))
33+
temp3 = int(input("What's the weather on Wednesday? "))
34+
temp4 = int(input("What's the weather on Thursday? "))
35+
temp5 = int(input("What's the weather on Friday? "))
36+
37+
average_temp = (temp1 + temp2 + temp3 + temp4 + temp5)/5
38+
print("It is " + month + " and the average temperature is " + str(average_temp) + " degrees celsius")
39+
40+
print("It is " + month.upper() + " and the average temperature is " + str(average_temp) + " degrees celsius")
41+
42+
favourite_animals = "dog\n\tcat\n\tfish\n\tchicken\n\tgoat"
43+
print(favourite_animals)
44+
45+
number = int(input("Pick a number between 0 and " + str(len(name) - 1) + "? "))
46+
print(name[number].upper())
47+
48+
str = "WelcometoPython"
49+
print(str[1:-1:2])
50+

0 commit comments

Comments
 (0)
0