Using Python 3: 1. Given variables first and last, each of which is associated w
ID: 3665671 • Letter: U
Question
Using Python 3:
1. Given variables first and last, each of which is associated with a str, representing a first and a last name, respectively. Write an expression whose value is a str that is a full name of the form "Last, First". So, if first were associated with "alan" and last with "turing", then your expression would be "Turing,Alan". (Note the capitalization! Note: no spaces!) And if first and last were "Florean" and "fortescue" respectively, then your expression's value would be "Fortescue,Florea"
2. Assume the variable date has been set to a string value of the form mm/dd/yyyy, for example 09/08/2010. (Actual numbers would appear in the string.) Write a statement to assign to a variable named dayStr the characters in date that contain the day. Then set a variable day to the integer value corresponding to the two digits in dayStr.
Explanation / Answer
#Python 3
#Save as firstLast.py
#This python program that splits the name last and first
#separated with sapce.
#extracts the first and last and capitalize the string starting
#letters and print to console.
def main():
#name string
str='turing, alan'
#call split method for space
#split returns list of strings
names=str.split(" ")
#get last name
last=names[0]
#get first name
first=names[1]
#capitalize and combine the two string
result=last.capitalize()+''+first.capitalize()
#print to console
print(result)
#calling main method
main()
-----------------------------------------------
Press F5 to run the progra from console
Sample output:
Turing,Alan
----------------------------------------------------------------------------------------
#Python 3
#Python program that set day value to dayStr
#print to console
def main():
#set '09/08/2010' to date
date='09/08/2010'
#call split with argumnet '/' method on date
array=date.split('/')
#set day value to dayStr
dayStr=array[0]
#print dayStr
print("day = ",dayStr)
#calling main method
main()
-------------------------------------------------------------
Press F5 to run the progra from console
Sample output:
day = 09
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.