Python Please help These are supposed to be basic ones so no
Python! Please help! These are supposed to be basic ones so not too crazy! Using CodeLab to enter homework answers in.
1. Write some code that reads in a name and an age into the variables name and age. It then prints the message \"The age of NAME is AGE\" on a line by itself, where NAME and AGE represent the values read into the variables name and age respectively.
For example, if your code read in \"Rohit\" and 70 then it would print out \"The age of Rohit is 70\" on a line by itself. There should NOT be a period in the output.
2.Assume that price is an integer variable whose value is the price (in US currency) in cents of an item. Write a statement that prints the value of price in the form \"X dollars and Y cents\" on a line by itself. So, if the value of price was 4321, your code would print \"43 dollars and 21 cents\". If the value was 501 it would print \"5 dollars and 1 cents\". If the value was 99 your code would print \"0 dollars and 99 cents\".
3.Write a statement that reads a word from standard input into firstWord.
Solution
Part 1 ) Please go through the code
# Hello World program in Python
Name=raw_input(\"Enter Name :\")
Age =raw_input(\"Enter Age :\")
print (\"Age Of \" +Name + \" Is \" +Age + \"!\")
Output Will be -
sh-4.3$ python main.py
Enter Name :a
Enter Age :11
Age Of a Is 11!
Part 2) try it Like -
price =(int)(raw_input(\"Enter The Price :\"))
dollar=price/100
cents=price%100
print (dollar , \" dollars and \", cents ,\"cents\")
Output Will be -
sh-4.3$ python main.py
Enter The Price :10000
(100, \' dollars and \', 0, \'cents\')
sh-4.3$ python main.py
Enter The Price :99
(0, \' dollars and \', 99, \'cents\')
Part 3) It will be like -
my_string = \"reads a word from standard input into firstWord\"
splitted = my_string.split()
first = splitted[0]
print (\"first\" ,first)
sh-4.3$ python main.py
(\'first\', \'reads\')
