Home › Forums › Grade 9 Python › Python Input Output Activities 18th March
- This topic has 13 replies, 12 voices, and was last updated 3 years, 3 months ago by
aanya03.
- AuthorPosts
- March 18, 2022 at 12:54 am #7414
Eamonn
KeymasterRecord your responses here please
March 18, 2022 at 1:51 am #7415Rafael
ParticipantIt firstly asks for the user to enter the name, then the student Id, and lastly course number. After writing all the answers to those questions, it labels in (Name, ID, and class enrollment)
String literal escape sequence is a sequence of characters from the source character set enclosed in double quotation marks. They are used to represent a sequence of characters.
When it changes to /t, it means ‘tab’, it is an escape sequence for the tab character.March 18, 2022 at 1:57 am #7416Rishi
Participantthe code first asks you to enter your name, then id and finally your course name. This is all recorded in a specific sequence which is code, id, and course name. Then the code prints your answer in the sequence. SO you are inputting your name id and course name then, the code in implementing it into the code
March 18, 2022 at 2:02 am #7417Kla
ParticipantThe code starts off by asking your name. After you have enter your name, it brings you to the second column which is asking for you to enter your student ID’s number. Finally, it will be asking your course number. After you’ve finished all of the questions. It writes like a summary of you. The double quotation marks is used to represent the sequence of characters.
March 18, 2022 at 2:08 am #7418Peam1223
Participantslide 1
1. enter name is displayed on the screen. then followed by enter student ID number after that its the course number and once you fill out all the information it will combine all the data in to one sentence stating the name, the id number, and the course.
2.i think that \n starts a new line.
3.\t is a space bar. it creates space.March 18, 2022 at 2:18 am #7419Chien493
ParticipantPrint the answer you enter the number. The int() function converts the specified value into an integer number.
March 18, 2022 at 3:07 am #7421Matthew Sparrow
ParticipantThe output I expected was an error, and it was an error. After you add “num1 = int(firstNumber) and num2 = int(secondNumber)” between lines 2 and 3 nothing changed yet because num1 doesn’t work with firstnumber and num2 doesn’t work with secondnumber. After I changed “difference = firstNumber – secondNumber” to “difference = num1 – num2” the code was working. the purpose of the function int() is to convert the specific value into an integer number. It made the number subtract one another to get the answer.
March 18, 2022 at 3:11 am #7422Fine
Participantname = input(“Enter name: “)
ID = input(“Enter your student ID number: “)
course = input(“Enter your course number: “)
print(name + “‘s ID is” + ID + “\nand is enrolled in “+ course)State what is displayed on the screen when you executed the program.
– Displayed on the screen is a place to enter your name, student ID, and course number. The final result is name+student ID+course number.The \n is a “string literal escape sequence” in python. What does this do?
– In Python, the new line character “\n” is used to create a new line. When inserted in a string all the characters after the character are added to a new line.Change the \n to \t and describe what happens to the program output.
– Replacing /t with /n will replace a line with a tab.March 18, 2022 at 3:19 am #7423Andrew
ParticipantThe int() function returns the numeric integer equivalent from a given expression. Expression whose numeric integer equivalent is returned. Using int() function we can convert the string input to integer. The below program will get two numbers from the user and print their sum. int() function converts any datatype to integer.
March 18, 2022 at 3:23 am #7424Fine
Participanta. What output do you expect?
– I expected that the function would not work.
b. What is the actual output
– The function did not work due to an error.
c. Revise the program in the following manner:
Between lines two and three add the following lines of code:
num1 = int(firstNumber)
num2 = int(secondNumber)
Next, replace the statement: difference = firstNumber – secondNumber
with the statement: difference = num1 – num2
Execute the program again. What output did you get?
– The code is now working. Num1-Num2=difference.
d. Explain the purpose of the function int().
– The int() function is used to convert a value into an integer number. The int() function returns an integer object made up of a number or a string x, or 0 if no arguments are provided. To be converted to an integer object, a number or string must be provided.
e. Explain how the changes in the program produced the desired output.
– Changes in the program make the code work properly and output the desired output. Without making the changes, the program would have errors that hinders the program from working.CODE:
firstNumber = input(“Enter a number: “)
num1 = int(firstNumber)
secondNumber = input(“Enter another number: “)
num2 = int(secondNumber)
difference = num1 – num2
print(“*” * 10)
print(“Difference = “, difference)March 18, 2022 at 3:32 am #7426May07
ParticipantThe int() function converts a provided statement to a numeric integer equivalent. We can turn a text into an integer using the int() function.
March 18, 2022 at 3:38 am #7427Fine
ParticipantPredict the output and execute the following lines of code.
name = input(“What is your name? “)
print(“Your name is”,Name)
a. Is the output what you would expect? Why or why not?
– Error, the variable ‘name’ is all in lowercase while the print ‘Name’ ‘N’ is uppercase, so it won’t work.b. How can you alter the code so that it functions properly?
– To make the function work, we change the letters to lowercase.
So we get the code:
name = input(“What is your name? “)
print(“Your name is”,name)March 20, 2022 at 1:01 pm #7428Bob
Participantname = input(“Enter name: “) This code sentence is for entering a name.
ID = input(“Enter your student ID number: “) This code requires you to enter the ID number (it is recommended to add a limit that you can only enter numbers)
course = input(“Enter your course number: “) Enter your course name.
print(name + “‘s ID is” + ID + “\nand is enrolled in “+ course) shows the result.April 15, 2022 at 6:54 am #7464aanya03
ParticipantIt first ask us to enter our name, then ID number, and the your course name. This is all recorded in this specific sequence which is your name, your ID number, and then your course name. So the input is the name, ID number and Course name, and your output is all of this coming out in a code sequence.
- AuthorPosts
- You must be logged in to reply to this topic.