#John Bible 11/29/21
#What I learned was how to use old style formatting and python-style formatting
#What I had problems with was task 2 personal information alignment but I overcame it by using the center instead of right and left.
year = 2017
price = 2.42011
print('The national average gas price in %d was $ %f' % (year, price))
year = 2017
price = 2.42011
print('The national average gas price in %i was $ %3.2f' % (year, price))
year = 2017
price = 2.42011
print('The national average gas price in %i was $ %08.2F' % (year, price))
year = 2017
price = 2.42011
print('The national average gas price in %d was $ %e' % (year, price))
year = 2017
price = 2.42011
print('The national average gas price in %d was $ %3.2e' % (year, price))
year = 2017
price = 2.42011
print('The national average gas price in %d was $ %3.2E' % (year, price))
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
print('The first name starts with: %c' % (first_name[0]))
print('The last name ends with the 2 chars: %s' %(last_name[-2:]))
from math import pi
print("Right adjusted: %20.2f" %(pi))
print("Left adjusted: %-20.2f" %(pi))
# [ ] Use the variables `F` and `C` to generate the following print outputs
#This will generate the following print outputs using the variables
'''
75 Fahrenheit = 23.888900 Celsius
75 Fahrenheit = 23.89 Celsius
75 Fahrenheit = 000023.889 Celsius
75 Fahrenheit = 23.889 Celsius
75 Fahrenheit = 23.889 Celsius
75 Fahrenheit = 2.389E+01 Celsius
75 Fahrenheit = 2.389e+01 Celsius
'''
F = 75
C = 23.8889
print("%i Fahrenheit = %f Celsius" %(F,C))
print("%i Fahrenheit = %2.2f Celsius" %(F,C))
print("%i Fahrenheit = %010.3f Celsius" %(F,C))
print("%i Fahrenheit = %-10.3f Celsius" %(F,C))
print("%i Fahrenheit = %10.3f Celsius" %(F,C))
print("%i Fahrenheit = %.3E Celsius" %(F,C))
print("%i Fahrenheit = %.3e Celsius" %(F,C))
# [ ] Use the string variables below to generate the following print outputs
# HINT: Set the name formatter width to 10 characters
#This will generate the following print outputs using the string variables
first_name = 'Tamara'
last_name = 'Babic'
'''
Name: Tamara Babic
Name: Tamara Babic
Name: Tamara Babic
Name: Tamara Babic
Name: Tamara Babic
Name: Tamara Babic
'''
print("Name: %s %s" %(first_name,last_name))
print("Name: %10s %10s" %(first_name,last_name))
print("Name: %s %14s" %(first_name,last_name))
print("Name: %10s %s" %(first_name,last_name))
print("Name: %s %09s" %(first_name,last_name))
print("Name: %s %s" %(first_name,last_name))
# [ ] The list `data` contains personnel information (Name, ID, email)
# Write a program to print out the data as follows:
#This will print out the data as follows
'''
Name ID Email
--------------------------------------------------
Suresh Datta 57394 suresh@example.com
Colette Browning 48539 colette@example.com
Skye Homsi 58302 skye@example.com
Hiroto Yamaguchi 48502 hiroto@example.com
Tobias Ledford 48291 tobias@example.com
Jin Xu 48293 jin@example.com
Joana Dias 23945 joana@example.com
Alton Derosa 85823 alton@example.com
'''
data = [["Suresh Datta", 57394, "suresh@example.com"], ["Colette Browning", 48539, "colette@example.com"], ["Skye Homsi", 58302, "skye@example.com"], ["Hiroto Yamaguchi", 48502, "hiroto@example.com"], ["Tobias Ledford", 48291, "tobias@example.com"], ["Tamara Babic", 58201, "tamara@example.com"], ["Jin Xu", 48293, "jin@example.com"], ["Joana Dias", 23945, "joana@example.com"], ["Alton Derosa", 85823, "alton@example.com"]]
N="Name"
I="ID"
E="Email"
print("%s %15s %09s" %(N,I,E))
print("--------------------------------------------------")
print("%s %10i %19s" %(data[0][0],data[0][1],data[0][2]))
print("%-17s %i %20s" %(data[1][0],data[1][1],data[1][2]))
print("%s %12i %17s" %(data[2][0],data[2][1],data[2][2]))
print("%-17s %i %19s" %(data[3][0],data[3][1],data[3][2]))
print("%-17s %i %19s" %(data[4][0],data[4][1],data[4][2]))
print("%s %10i %19s" %(data[5][0],data[5][1],data[5][2]))
print("%s %16i %16s" %(data[6][0],data[6][1],data[6][2]))
print("%s %12i %18s" %(data[7][0],data[7][1],data[7][2]))
print("%s %10i %18s" %(data[8][0],data[8][1],data[8][2]))
year = 2017
price = 2.42011
print('The national average gas price in {:d} was $ {:f}'.format(year, price))
year = 2017
price = 2.42011
print('The national average gas price in {0:d} was $ {1:3.2F}'.format(year, price))
year = 2017
price = 2.42011
print('The national average gas price in {y:d} was $ {p:1.2e}'.format(y = year, p = price))
year = 2017
price = 2.42011
print('The national average gas price in {:d} was $ {:010.2f}'.format(year, price))
first_name = input("Enter your first name: ")
last_name = input("Enter your last name: ")
print('The first name starts with: {:s}'.format(first_name[0]))
print('The last name ends with the 2 chars: {:s}'.format(last_name[-2:]))
from math import pi
print('Right adjusted : {:<20.2f}'.format(pi))
print('Center adjusted: {:^20.2f}'.format(pi))
print('Left adjusted : {:>20.2f}'.format(pi))
from math import pi
# Padding with zeros
print('Right adjusted : {:0<20.2f}'.format(pi))
print('Center adjusted: {:0^20.2f}'.format(pi))
print('Left adjusted : {:0>20.2f}'.format(pi))
from math import pi
# Padding with underscore characters
print('Right adjusted : {:_<20.2f}'.format(pi))
print('Center adjusted: {:_^20.2f}'.format(pi))
print('Left adjusted : {:_>20.2f}'.format(pi))
# [ ] Use Python-style formatting and the variables `F` and `C` to generate the following print outputs
#This will use python-style formatting and the variables F and C to generate the following print outputs
'''
75 Fahrenheit = 23.888900 Celsius
75 Fahrenheit = 23.89 Celsius
75 Fahrenheit = 0000023.89 Celsius
75 Fahrenheit = 23.889 Celsius
75 Fahrenheit = 23.889 Celsius
75 Fahrenheit = 23.889 Celsius
75 Fahrenheit = 2.389E+01 Celsius
'''
F = 75
C = 23.8889
print("{:d} Fahrenheit = {:f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:2.2f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:010.2f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:<10.3f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:^10.3f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:>10.3f} Celsius" .format(F,C))
print("{:d} Fahrenheit = {:.3E} Celsius" .format(F,C))
# [ ] Use Python-style formatting and the string variables below to generate the following print outputs
# HINT: Set the name formatter width to 10 characters
#This will use python-style formatting and the string variables below to generate the following print outputs
first_name = 'Tamara'
last_name = 'Babic'
'''
Name: Tamara Babic
Name: Tamara Babic
Name: Tamara____ _____Babic
Name: __Tamara__ __Babic___
Name: ____Tamara Babic_____
Name: Tamara Babic
'''
print("Name: {:s} {:s}" .format(first_name,last_name))
print("Name: {:s} {:>14s}" .format(first_name,last_name))
print("Name: {:s}____ _____{:>05s}" .format(first_name,last_name))
print("Name: __{:s}__ __{:s}___" .format(first_name,last_name))
print("Name: ____{:s} {:s}_____" .format(first_name,last_name))
print("Name: {:>10s} {:s}" .format(first_name,last_name))
# [ ] The list `data` contains personnel information (Name, ID, email)
# Write a program using Python-style formatting to print out the data as follows:
#This will use python-style formatting to print out the data as follows
'''
Name | ID | Email
________________________________________________________
Suresh Datta | 57394 | suresh@example.com
Colette Browning | 48539 | colette@example.com
Skye Homsi | 58302 | skye@example.com
Hiroto Yamaguchi | 48502 | hiroto@example.com
Tobias Ledford | 48291 | tobias@example.com
Jin Xu | 48293 | jin@example.com
Joana Dias | 23945 | joana@example.com
Alton Derosa | 85823 | alton@example.com
'''
data = [["Suresh Datta", 57394, "suresh@example.com"], ["Colette Browning", 48539, "colette@example.com"], ["Skye Homsi", 58302, "skye@example.com"], ["Hiroto Yamaguchi", 48502, "hiroto@example.com"], ["Tobias Ledford", 48291, "tobias@example.com"], ["Tamara Babic", 58201, "tamara@example.com"], ["Jin Xu", 48293, "jin@example.com"], ["Joana Dias", 23945, "joana@example.com"], ["Alton Derosa", 85823, "alton@example.com"]]
N="Name"
I="ID"
E="Email"
print("{:>12s} | {: >05s} | {: >12s}" .format(N,I,E))
print("----------------------------------------------------------")
print("{:^20s} | {:^10d} | {:>20s}" .format(data[0][0],data[0][1],data[0][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[1][0],data[1][1],data[1][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[2][0],data[2][1],data[2][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[3][0],data[3][1],data[3][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[4][0],data[4][1],data[4][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[5][0],data[5][1],data[5][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[6][0],data[6][1],data[6][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[7][0],data[7][1],data[7][2]))
print("{:^20s} | {:^10d} | {:>20s}" .format(data[8][0],data[8][1],data[8][2]))