Computer Science, asked by kanishkajha095, 10 months ago

a}find output in Python coding​
b} find error in Python code

Attachments:

Answers

Answered by rishitbaitule
0
This is for a) I am unable to upload b)
Pl mark me the brainliest
b) File "./Playground/file0.py", line 4
print"your name and age is"name+age
^
SyntaxError: invalid syntax

This is the error in both the cases
Attachments:
Answered by Equestriadash
11

a) Given codes:

x = 10

x = x + 10

x = x - 5

print(x)

x, y = x - 2, 22

print(x, y)

Output:

15

13 22

Step-by-step explanation:

x = 10   #value assigned to x is 10

x = x + 10   #variable 'x' has been assigned the value of x + 10, ⇒ 10 + 10

x = x - 5     #variable 'x' has been assigned the value of x - 5, ⇒ 20 - 5

print(x)     #prints the value of 'x', ⇒ 15

x, y = x - 2, 22     #variables 'x' and 'y' have been assigned the values of x - 2 and 22 respectively, ⇒ 15 - 2, 22

print(x, y)     #prints the values of 'x' and 'y', ⇒ 13 22

b) Given code:

name = "aman"

age = 26

print("Your name and age is", name + age)

Output:

Traceback (most recent call last):

 File "<pyshell#3>", line 1, in <module>

   print("Your name and age is", name + age)

TypeError: can only concatenate str (not "int") to str

Error:

The data type of the variable 'name' is that of a string value, whereas the data type assigned to variable 'age' is an integer type. You cannot add a string value and an integer data type. Doing so will only result in an error.

Solution:

You can convert the data type assigned to 'age' to that of a string instead by adding the value in quotes, or you could separate the values in the print statement.

Correct code (1):

name = "aman"

age = "26"

print("Your name and age is", name + age)

[Keep in mind, doing so, there will be no space between the name and the age. This is why the second code (given below) is most preferable.)]

Correct code (2):

name = "aman"

age = 26

print("Your name and age is", name, age)


Equestriadash: Thanks for the Brainliest!
Similar questions