-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
92 lines (59 loc) · 1.65 KB
/
Copy pathpractice.py
File metadata and controls
92 lines (59 loc) · 1.65 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
hello='Hello'
print(f'{hello[::-1]}')
for letter in 'Hello':
if letter == 'e':
continue
print(letter)
word = 'hello'
for index, letter in enumerate(word):
print(f'index {index} for letter {letter}')
list1 = [1, 2, 3]
list2 = ['a', 'b', 'c']
for item in zip(list1, list2):
print(item)
print(list(zip(list1, list2)))
dic = {'k1', 123}
print('k1' in dic)
# name = input("What's your name?")
# print(name)
mylist = [num**2 for num in range(0,11) if num%2 == 0]
print(mylist)
celcius = [0, 10, 20, 30.5]
fahrenheith = [((9/5)*temp + 32) for temp in celcius]
print(fahrenheith)
results = [ x if x % 2 == 0 else 'ODD' for x in range(0, 10)]
print(results)
mylist = [x * y for x in [1, 2, 3] for y in [1, 10, 100]]
print(mylist)
##################
# Practice
str = 'Print only the words that start with an s in this sentence'
for word in str.split():
if word[0] == 's':
print(word)
print([num for num in range(1, 51) if num % 3 == 0])
for word in str.split():
if len(word) % 2 == 0:
print(f'{word} is even')
print(list(range(0, 11, 2)))
for num in range(1, 101):
if num % 3 == 0 and num % 5 == 0:
print(f'{num} FizzBuzz')
elif num % 3 == 0:
print(f'{num} Fizz')
elif num % 5 == 0:
print(f'{num} Buzz')
else:
print(num)
str = 'Create a list of the first letters of every word in the list below'
print([letter[0] for letter in str.split()])
##################
'''
Description of a function
'''
def say_hello(name='NAME'):
return 'Hello ' + name
print(say_hello('Al'))
def check_dog(mystring):
return 'dog' in mystring.lower()
print(check_dog('my dog is here'))