-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic-code.py
52 lines (35 loc) · 1.3 KB
/
basic-code.py
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
import random
def userTests():
name = input("What is your name? ")
age = input("How old are you? ")
print("Hello " + name + ", you are " + age + " years old.")
def aleatoryListNumber():
numbers = [random.randint(1, 100) for i in range(20)]
return numbers
def sumNumberPair():
# Hacer una lista de numeros aleatorios del 1 al 100 y tomar 20
aleatoryList = aleatoryListNumber()
print("The list is: " + str(aleatoryList))
# Extraer y sumar los numeros pares de la lista
evenNumbers = sum([i for i in aleatoryList if i % 2 == 0])
print("The sum of the even numbers is: " + str(evenNumbers))
def orderStrings():
# Hacer una lista de palabras aleatorias y ordenarlas alfabeticamente
words = ["tv", "dog", "glasses", "computer", "code", "friday", "Canada", "Japan", "mom", "learing"]
words.sort()
[print(x) for x in words]
def isPair():
number = int(input("What is the number?"))
if (number % 2 == 0): print("Is pair")
else: print("Is not pair")
def orderNumber():
# Hacer una lista de numeros aleatorios del 1 al 100 y tomar 20
aleatoryList = aleatoryListNumber()
print(str(aleatoryList))
aleatoryList.sort()
print("The list ordered is: " + str(aleatoryList))
userTests()
sumNumberPair()
orderStrings()
isPair()
orderNumber()