0% found this document useful (0 votes)
30 views

A Python Function

Uploaded by

skylarzhang66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

A Python Function

Uploaded by

skylarzhang66
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

# Create a python function that given two integer numbers,

# return their product only if the product is equal to or lower than 1000.
# Otherwise, return their sum.
def product_or_sum():
num1 = int(input('enter the first number: '))
num2 = int(input('enter the second number: '))
if num1 * num2 <= 1000:
print(num1*num2)
else:
print(num1+num2)
product_or_sum()

# Create a python function that takes three input() integer numbers,


# then display only the biggest number.
# Please avoid using max()
def biggest_num():
num1 = int(input('enter the first number: '))
num2 = int(input('enter the second number: '))
num3 = int(input('enter the third number: '))
if num1 >= num2 and num1 >= num3:
print('The largest number is:', num1)
elif num2 >= num1 and num2 >= num3:
print('The largest number is:', num2)
else:
print('The largest number is:', num3)
biggest_num()

# Create a python program for the situation below:


# A shop will give discount of 10% if the cost of purchased quantity is more than
1000.
# Ask the user for quantity.
# Suppose, one unit will cost 100.
# Judge and print total cost for the user.
quantity = int(input('please tell me your purchased quantity: '))
total_cost = quantity * 100
if total_cost > 1000:
print('The total cost is', 0.9*total_cost)
else:
print('The total cost is', total_cost)
# Create a python function that takes a name,
# if the name is ‘john’ or ‘mary’, the return the password(12345),
# if other names, no access.
def password():
name = input('Enter your name: ')
name = name.lower()
answer = ['mary', 'john']
if name in answer:
print('12345')
else:
print('no access')

password()

# Create a python program that let user to create password.


# The password should include a ‘!’ in it and the total number of characters should be
at least 8.
# If not eligible, try it again.
password = input('Create password with a ‘!’ and at least 8 characters: ')
if '!' in password and len(password) >= 8:
print('Password is valid. Your password has been set.')
else:
print('Password is invalid. Please try it again')

# Create a Python program to check if the number is divisible by both 5 and 7 or not.
# For example: input: 35 output: the number is divisible by 5 and 7.
# Input: Get the number from the user
num = int(input('enter a number: '))
if num % 5 == 0 and num % 7 == 0:
print('The number is divisible by 5 and 7.')
else:
print('The number is not divisible by both 5 and 7.')

You might also like