Created
May 17, 2024 04:52
-
-
Save lw13377/f785f9729e2d2b0eb865c6bc49216e3b to your computer and use it in GitHub Desktop.
lesson 5 homework
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
# Homework Lesson 5 - Workshop - Homework | |
# READ CAREFULLY THE EXERCISE DESCRIPTION AND SOLVE IT RIGHT AFTER IT | |
# Challenge 1 | |
# Make a number Positive | |
# | |
# Create a variable called my_number and set it to any integer value. | |
# Write code to make the number positive if it's negative, and keep it | |
# as is if it's already positive or zero. | |
# | |
# Example: | |
# Input: -3 => Output: 3 | |
# Input: 5 => Output: 5 | |
a = int(input("give me a number ")) | |
a = abs(a) | |
print(a) | |
# --------------------------------------------------------------------- | |
# Challenge 2 | |
# BinGo! | |
# | |
# If the number is divisible of 3, print “Bin” | |
# If the number is divisible of 7, print “Go” | |
# For numbers which are divisible of 3 and 7, print “BinGo” | |
# Otherwise, print the original number: “{number} is just a number” | |
numb = int(input("give me a number ")) | |
if numb % 3 == 0 and numb % 7 == 0: | |
print("BinGo") | |
elif numb % 3 == 0: | |
print("Bin") | |
elif numb % 7 == 0: | |
print("Go") | |
else: | |
print((numb) , "number is not divisible by 3 or 7") | |
# --------------------------------------------------------------------- | |
# Challenge 3 | |
# Find the middle number | |
# | |
# Given three different numbers x, y, and z, find the number that is neither | |
# the smallest nor the largest and print it. | |
# | |
# Example: | |
# x = 1, y = 5, z = 3 => Output: 3 | |
x = 5 | |
y = 10 | |
z = 20 | |
if x > y and x < z or x < y and x > z: | |
print("x") | |
elif z < x and z > y or z > x and z < y: | |
print("z") | |
else: | |
print("y") | |
# --------------------------------------------------------------------- | |
# Challenge 4 | |
# Palindrome Numbers | |
# | |
# Ask a user to input a number. | |
# Write a program to check if the given number is a palindrome. | |
# It should print True if the number is a palindrome and False if it is not. | |
# | |
# Palindrome number: 121, 898 | |
num = int(input("give me a number ")) | |
string = str(num) | |
if string == string[::-1]: | |
print("True") | |
else: | |
print("False") | |
# --------------------------------------------------------------------- | |
# Challenge 5 | |
# Reverse a string | |
# | |
# You're part of a team working on analyzing customer reviews for a new video game. | |
# Due to a software glitch, some reviews have been recorded in reverse with punctuation | |
# at the beginning instead of the end. Your task is to correct these reviews so that they | |
# are in the correct order and the punctuation is appropriately placed at the end of the | |
# sentence or word. | |
# | |
# Example: "tcefreP!" -> Perfect! | |
review = (input("give me a review: ")) | |
if review[0] == "!": | |
print(review[::-1]) | |
else: | |
print(review) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment