# Data Processing and Visulisation with Python

### Absolute value

Write a Python program to input a float (negative or positive) from user, and output its absolute value.

Note: please do not use absolute functions from other modules. Write your own version.

n=float(input("Please input a float:"))
if n>0:
print(f"The absolute value of float {n} is: {n}")
else:
print(f"The absolute value of float {n} is: {-n}")


Better method

n=float(input("Please input a float:"))
print(f"The absolute value of float {n} is: {n if n>=0 else -n}") ### Convert between o ^o C and o ^o F

Write a Python program to convert temperature between Celsius and Fehrenheit.

Hint:

• To extract the last character from string s, you can use s[-1].
• To extract the characters except the last from string s, you can use s[:-1]
n=input("Please input temperature degrees (ending with C for Celsius and F for Fehrenheit):")
a=n[-1]
b=float(n[:-1])
if a == "F":
print(f"{b} degrees in Fehrenheit is {(b-32)*5/9} degrees in Celsius.")
else:
print(f"{b} degrees in Celsius is {(b*9/5+32)} degrees in Fehrenheit.") ### Dog’s years

Write a Python program to calculate a dog’s age in dog’s years.

Note: For the first two years, a dog year is equal to 10.5 human years. After that, each dog year equals 4 human years.

dog_year=float(input("Please input a dog's age in human years:"))
if dog_year<=2:
print(f"The dog's age in dog's years is {(dog_year*10.5)}")
else:
print(f"The dog's age in dog's years is {(dog_year-2)*4+10.5*2}") ### Median of three

Write a Python program to find the median of three values.

a=float(input("Input first number:"))
b=float(input("Input second number:"))
c=float(input("Input third number:"))
if a>b>c or c>b>a:
print(f"The median is {b}")
elif a>c>b or b>c>a:
print(f"The median is {c}")
else:
print(f"The median is {a}") ### Next second

Write a Python program to input hour, minute and second from user, then print out the time of next second.

h=int(input("Please input hour (0~23):"))
print(f"Input time is: {h}:{m}:{s}")

if s == 59:
a=0
if m == 59:
b=0
if h == 23:
c=0
else:
c=h+1
else:
b=m+1

else:
a=s+1

print(f"The time of next second is:{a}:{b}:{b}") ### Positive, negative or zero

Write a Python program to check if an input number is positive, negative or zero!

n=float(input("Please input a number:"))
if n<0:
print(f"{n} is negative")
elif n==0:
print(f"{n} is zero")
else:
print(f"{n} is positive") ### Around 888

Write a Python program to test if an input number is within 88 of 888.

n = float(input("Please input a number:"))
if 800<=n<=976:
print(f"{n} is within 88 of 888")
else:
print(f"{n} is not within 88 of 888") ### Even or odd (new version)

Write a Python program to input an integer, then output if the integer is odd or even.

n=int(input("Please input an integer:"))
if n%2 ==0:
print(f"{n} is an even integer.")
else:
print(f"{n} is an odd integer.") 09-16 42 05-24 974
03-01 1028
04-12 105
03-26 886
05-16 293
09-16 19
04-13 464
01-03 561
01-29 22