This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a program that asks the user to enter their name and their age. Print out a message addressed to them | |
# that tells them the year that they will turn 100 years old. | |
# | |
import datetime | |
name = input("Hello! Please enter your name: ") | |
print("Hello " + name) | |
age = int(input("Enter your age: ")) | |
year_now = datetime.datetime.now() | |
#print(year_now.year) | |
print("You will turn 100 in " + str(int(100-age) + int(year_now.year))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create a program that asks the user to enter their name and their age. Print out a message addressed to them | |
# that tells them the year that they will turn 100 years old. | |
# Add on to the previous program by asking the user for another number | |
# and printing out that many copies of the previous message. | |
import datetime | |
def call1(): | |
print("You will turn 100 in " + str(int(100-age) + int(year_now.year))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask the user for a number. Depending on whether the number is even or odd. | |
# print out an appropriate message to the user. | |
num = int(input("Enter a number: ")) | |
if num % 2 == 0: | |
print("Your number is even") | |
else: | |
print("Your number is odd") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask the user for a number. Depending on whether the number is even or odd. | |
# print out an appropriate message to the user. | |
# If the number is a multiple of 4, print out a different message. | |
num = int(input("Enter a number: ")) | |
if num % 2 == 0: | |
if num % 4 == 0: | |
print("Your number is a multiple of 4") | |
else: | |
print("Your number is even") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask the user for two numbers: one number to check (call it num) and one number to divide by (check). | |
# If check divides evenly into num, tell that to the user. | |
# If not, print a different appropriate message. | |
num = int(input("Enter a number: ")) | |
check = int(input("Enter a number to divide by: ")) | |
if num % check == 0: | |
print("Yusssss") | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Take a list, say for example this one: | |
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
# and write a program that prints out all the elements of the list that are less than 5. | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
new_list = [] | |
num = 5 | |
for i in a: | |
if i<num: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask the user for a number and return a list that contains only elements | |
# from the original list a that are smaller than that number given by the user. | |
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
new_list = [] | |
num = input("Enter a number to be compared with: ") | |
for i in a: | |
if i<num: | |
new_list.append(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a Python program to sum all the items in a list. | |
# use function | |
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
def sum_list(a): | |
sum_test = 0 | |
for i in a: | |
sum_test += i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a Python program to multiplies all the items in a list. | |
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
def multiply_items(a): | |
mult = 1 | |
for i in a: | |
mult = mult*i | |
return mult |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Write a Python program to get the largest number from a list. | |
# Using function | |
# a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
def max_num(a): | |
flag = 0 | |
for i in a: | |
if i > flag: | |
flag = i |
OlderNewer