Input
Input అంటే ఏమిటి?
Python program నడుస్తున్నప్పుడు user నుండి information తీసుకోవడానికి input() function ఉపయోగిస్తాము. User keyboard ద్వారా value ఇస్తాడు. Python ఆ value ను తీసుకుని program లో ఉపయోగిస్తుంది.
Input ఎందుకు ఉపయోగిస్తాము?
ఒకే program ను వేర్వేరు user values తో run చేయడానికి input అవసరం. ఉదాహరణకు, ప్రతి user పేరు వేర్వేరుగా ఉంటుంది. Program లో పేరు ముందుగానే రాయకుండా, user దగ్గర నుంచి తీసుకోవచ్చు.
Input ఎలా పనిచేస్తుంది?
- Python
input()function ను execute చేస్తుంది. - Prompt message ఉంటే అది screen పై కనిపిస్తుంది.
- Program user input కోసం వేచి ఉంటుంది.
- User value type చేసి Enter నొక్కుతాడు.
- ఆ value variable లో store అవుతుంది.
input() ద్వారా వచ్చే value default గా string. అందువల్ల number కావాలంటే, గత lesson లో నేర్చుకున్న type conversion ఉపయోగించాలి. ఉదాహరణకు, int(input()).
Input ఎక్కడ ఉపయోగపడుతుంది?
- User పేరు, city లేదా email తీసుకోవడానికి
- Quiz answers తీసుకోవడానికి
- Calculator లో values తీసుకోవడానికి
- Forms మరియు interactive programs తయారు చేయడానికి
Simple Explanation
input() అంటే user నుండి data తీసుకోవడం. ఉదాహరణకు name = input("Enter your name: ") అని రాస్తే, screen పై message కనిపిస్తుంది. User పేరు type చేసి Enter నొక్కిన తర్వాత, ఆ పేరు name variable లో store అవుతుంది.
గమనించాల్సిన ముఖ్యమైన విషయం: input() ఎల్లప్పుడూ value ను string గా ఇస్తుంది. కాబట్టి number input ను calculation కోసం ఉపయోగించాలంటే int() లేదా float() తో convert చేయాలి.
Real-Life Example
ఒక hotel reception వద్ద customer తన పేరు చెబుతాడు. Receptionist ఆ పేరును నమోదు చేస్తాడు. అదే విధంగా Python లో input() user చెప్పే information ను తీసుకుని variable లో store చేస్తుంది.
Code Examples
User పేరు తీసుకోవడం
name = input("Enter your name: ")
print("Welcome,", name)
ఈ program user ను పేరు అడిగి, ఆ పేరుతో welcome message చూపిస్తుంది. input() ద్వారా వచ్చిన పేరు name variable లో store అవుతుంది.
Enter your name: Ravi Welcome, Ravi
Line-by-Line Explanation
ఈ line లో input() function user ను పేరు అడుగుతుంది. User value type చేసి Enter నొక్కిన తర్వాత, ఆ value name variable లో store అవుతుంది. ఈ value default గా string గా ఉంటుంది.
ఈ line print() function ద్వారా welcome message మరియు user ఇచ్చిన పేరును screen పై చూపిస్తుంది. print() లో comma ఉపయోగించడం వల్ల రెండు values మధ్య space వస్తుంది.
Try It
Try this Python code:
color = input("Enter your favorite color: ")
print("Your favorite color is", color)
Practice
Practice: User ను అతని పేరు మరియు city అడిగి, రెండు values ను screen పై చూపించే Python program రాయండి.
Hint: input() ను రెండు సార్లు ఉపయోగించి values ను రెండు variables లో store చేయండి. తర్వాత print() తో వాటిని చూపించండి.
Practice: User ను అతని favorite color అడిగి, ఆ color తో ఒక sentence print చేయండి.
Hint: ఒక variable లో input() value ను store చేసి, దాన్ని print() లో ఉపయోగించండి.
Common Mistakes
input() లో prompt message ఇవ్వకపోవడం వల్ల user ఏ value ఇవ్వాలో అర్థం కాకపోవచ్చు.input("Enter your name: ") లాగా clear prompt message ఇవ్వండి.
input() ద్వారా వచ్చిన number ను నేరుగా calculation చేయడానికి ప్రయత్నించడం.input() value string కాబట్టి, number కోసం int(input()) లేదా decimal value కోసం float(input()) ఉపయోగించండి.
Input ను variable లో store చేయండి. ఉదాహరణకు,
name = input("Enter your name: ").
print("name").Variable value చూపించడానికి quotes లేకుండా
print(name) అని రాయండి.
Interview Questions
Python లో user input తీసుకోవడానికి ఏ function ఉపయోగిస్తారు?
Answer: input() function ఉపయోగిస్తారు.
input() function return చేసే value యొక్క default type ఏమిటి?
Answer: input() function value ను string type గా return చేస్తుంది.
input() function లో prompt అంటే ఏమిటి?
Answer: User ఏ value ఇవ్వాలో తెలియజేసే message ను prompt అంటారు. ఉదాహరణకు, input("Enter your name: ").
User నుండి integer input ఎలా తీసుకుంటారు?
Answer: age = int(input("Enter your age: ")) అని రాయవచ్చు.
Exam Questions
Python లో input తీసుకోవడానికి ఉపయోగించే function ఏది?
Answer:
input().
క్రింది code లో user ఇచ్చిన value ఏ variable లో store అవుతుంది? city = input("Enter city: ")
Answer:
User ఇచ్చిన value city variable లో store అవుతుంది.
name = input("Enter name: ") code లో prompt message ఏది?
Answer:
Enter name: అనేది prompt message.
input() ద్వారా వచ్చిన value number గా కావాలంటే ఏ function ఉపయోగించాలి?
Answer:
Integer కోసం int(), decimal number కోసం float() ఉపయోగించాలి.
Quick Revision
input()function user నుండి data తీసుకుంటుంది.- User input కోసం program కొంతసేపు వేచి ఉంటుంది.
input()ద్వారా వచ్చిన value default గా string.- Input ను variable లో store చేసి తర్వాత ఉపయోగించవచ్చు.
- Number input కోసం
int()లేదాfloat()తో type conversion చేయాలి. - Clear prompt message ఇస్తే user కు ఏ value ఇవ్వాలో అర్థమవుతుంది.
