Check Point 3.4
1. What is a variable?
Answer: A variable is a named location that refers to a value and whose values can be used and processed during run.
2. Why is a called symbolic variable?
Answer: In Python, Variables are known as Symbolic variables, because these are used as named labels.
3. Create variables for the following: (i) to hold train number (ii) to hold the name of a subject (iii) to hold balance amount in a bank account (iv) to hold a phone number
Answer: (i) trnNo = 25869
(ii) subName = “Informatics Practices”
(iii) balanceAmount = 25698.36
(iv) phoneNumber = ‘+91 9541 954 258’
4. What do you mean by dynamic typing of a variable? What is the caution you must take care of?
Answer: In Python, a variable pointing to a value of a certain type, can be made to point to a value of different type, called Dynamic Typing.
Example: x = 2569 # x pointing integer
x = 25698.398 # now x pointing float
x = “anjeevsinghacademy.com” # x pointing a string
Caution with Dynamic Typing
Need to ensure that variables with right type of values should be used in expressions.
5. What happens when you try to access the value of an undefined variable?
Answer: Accessing the value of an undefined variable, will show an error called Name Error.
In Python, a variable is defined only when we assign some value to it.
6. What is wrong with the following statement?
Number = input (“Number”)
Sqr = Number*Number
Answer:
Number = input (“Number”)
input() function in Python return a string value. So Number is a String data type.
Sqr = Number*Number
Because Number is string, so we cannot perform the multiplication operation with Number.
7. Write Python code to obtain the balance amount.
Answer:
amount = float(input(“Enter Amount :”))
expense = float(input(“Enter Expense :”))
balance_amount = amount – expense
print(“Balance Amount :”, balance_amount)
8. Write code to obtain fee amount and then calculate fee hike as 10% of fees (i.e. fees x 0.10 ).
Answer :
fee_amount = float(input(“Enter Fee Amount :”))
fee_hike = fee_amount * 0.10
print (“Fee Hike :Rs. ”, fee_hike)