import numpy as np
import randomRandom Homework
Module 1: Python Fundamentals
ls_exercises = [
"1.5",
"1.6",
"1.10",
"1.17",
"1.18",
"2.9",
"2.10",
"2.11",
"2.12",
"3.6",
"3.8",
"3.9",
"3.10",
"4.14",
# "4.15",
"4.18",
"4.19",
"4.20",
"4.21",
"4.25"
]ls_students = [
"MATISSE VALENTINA RITA STEPHAN AAFTINK-DE LUCA",
"MATHIAS ANDRES ALVAREZ MORALES",
# "ADAM HENRYK BAJER",
# "ADRIÁN CASELLAS SANSO",
"PAUL ANDRE PLERRE CHABERT",
"FERNANDO CORDERO MARTÍN-CARO",
"LUIS FERNANDO DIEZ JORRETO",
"QIN YU EGUÍA FERNÁNDEZ",
"MIGUEL FERNÁNDEZ ORTIZ",
"PABLO GARMA TARDÍO",
# "IGNACIO GIMENO ALEMANY",
"ZOYA INAARA HAIDER",
# "EVA JU?NA",
"PANAGIOTIS KAMARINOS",
"NOA KESERI",
# "DONOVAN LOWE",
# "SEBASTIAN ALEXANDER LUBCZONOK ALEXANDER",
"MARIAM MOHAMED ESMAT EZZAT",
"OMAR MOHAMED KAMAL",
"DARIUS-LUCA PETRUTI",
"MARÍA RIVERA LÓPEZ",
"CARLOS SALDAÑA TEJERA",
"ANA SANTOS ESCORIAL",
"TAMARA SHOPOVA",
"PABLO TORRES COLOMINA",
"ZIPENG YANG"
]
print(len(ls_students))# Pick a random exercise
print(random.choice(ls_students))
print(random.choice(ls_exercises))points = [1, 1, 1, 1, 1]
print(np.mean(points))a = 1
b = 1
c = -6
def f(x):
return (a * x**2) + (b * x) + c
def g(x):
return (a / x)# 3.10
n = int(input())
a=0
for i in range (1,n):
if n%i==0:
a += i # a = a + i
if a==n:
print(f"{n} is a perfect number")
else:
print(f"{n} isn't a perfect number")def num(n):
for i in range(2,n):
if n%i==0:
return False
else:
return True
def close(n):
for i in range(n,2,-1):
if num(i)==True :
if n%i==0:
l=i
else:
l=1
return l# Exercise 1.17: Character Replacement
sample_input = "excellent"
string = ''
sample_input = list(sample_input)
first_entry = sample_input[0]
for i in range(len(sample_input)-1):
if sample_input[i+1] == first_entry:
sample_input[i+1] = '$'
for i in range(len(sample_input)):
string = string + sample_input[i]
print(string)num1=int(input("Input a number "))
happy=False
for i in range (0,100):
sum = 0
while num1>0:
sum = (num1%10)**2
num1=num1//10
if sum == 1:
happy=True
break
num1=sum
print(happy)Write a Python code that finds the first occurrence of the substring “cat” and outputs it. It must work both for lowercase and uppercase.
word = "CAtastrophe"
word_lower = word.lower()
idx = word_lower.find("cat")
print(word[idx:idx+3])