+ 2
Guys what is function of if and else?You can give me a explain
Im new;-;-;-;
3 Answers
+ 6
For logic operations.
Example in a job application
if age > 18: #If age is 19 or more, this condition will be True, and print "Eligible"
print("Eligible")
else: #If age is 18 below and the if above is false, it will print "Underage"
print("Underage")
For more details:
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2277/
I also recommend to check comment sections in every quizzes and lessons, people gives examples, explanations and some extra knowledge.
+ 6
Sololearn already explained it well.
The if statement allows you to check a condition and run some statements, if the condition is True.
The else statement can be used to run some statements when the condition of the if statement is False.
For example,
x = 4
if x == 5:
print("Yes")
else:
print("No")
#output: No
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2278/
+ 2
If you want to really know then solve some problem and play with the code you will understand more easily like that way :-
á´Ęá´ĘĘá´á´s -
1)Take two int values from user and print greatest among them.
2)A shop will give discount of 10% if the cost of purchased quantity is more than 1000.
Ask user for quantity
Suppose, one unit will cost 100.
Judge and print total cost for user.
3)A company decided to give bonus of 5% to employee if his/her year of service is more than 5 years.
Ask user for their salary and year of service and print the net bonus amount.
--------------------------------------------------------------