Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Implement a program that requests a list of words from the user and then prints

each word in the list that is not ‘secret’.

Enter list of words: [‘cia’,’secret’,’mi6’,’isi’,’secret’]

Expected output:

cia

Mi6

Isi

Syntax:
words=input("Enter list of words:")
splitted= words.split(",")
for x in splitted:
if "secret" not in x:
print(x)

OUTPUT:
Implement a program that requests a list of student names from the user and prints
those names that starts with letters A through M.

Enter list: [‘Ellie’, ‘Stevie’, ‘Sam’, ‘Owen’, ‘Gavin’]

Expected output:

Ellie

Gavin

Syntax:
words=input("Enter list:")
split= words.split(",")
for word in split:
if word[0] in 'ABCDEFGHIJLM':
print(word)

OUTPUT:
Implement a program that requests a non empty list from the user and prints on the
screen a message giving the first and last element of the list.

Enter a list: [3, 5, 7, 9]

Expected output:

The first list element is: 3

The last list element is :9

Syntax:

list = input("Enter a list:")

print("The first list element is:" + list[0])


print("The last list element is:" + list[-1])

OUTPUT:
Implement a program that requests a positive integer n from the user and prints the
first four multiples of n:

Expected output:

Enter n: 5

10

15

Syntax:
n=input("Enter n:")

for x in range(4):
multiples=int(n) * x
print(multiples)

OUTPUT:
Implement a program that requests an integer n from the user and prints on the
screen the squares of all numbers from 0 up to, but not including n.

Expected Output:

Enter n: 4

Syntax:

n=input("Enter n:")

for x in range(int(n)):
square=x**2
print(square)

OUTPUT:
Implement a program that requests a positive integer n and prints on the screen all
the positive divisors of n. Note: 0 is not a divisor of any integer and n divides itself.

Expected Output:

Enter n: 49

49

Syntax:
n=int(input("Enter n:"))
for x in range(1,n+1):
if(n%x==0):
print(x)

OUTPUT:
Implement a program that requests four numbers (integer or floating-point) from
the user. Your program should compile the average of the first three numbers and
compare the average to the fourth number. If they are equal, your program should
print ‘Equal’ on the screen.

Expected Output:

Enter first number: 4.5


Enter second number: 3
Enter third number: 3
Enter last number: 3.5

Equal

Syntax:
a= float(input("Enter first number:"))
b= float(input("Enter second number:"))
c= float(input("Enter third number:"))
d= float(input("Enter last number:"))

e =(a + b + c)/3

if e==d:
print("Equal")

OUTPUT:

You might also like