#18 Python Tutorial for Beginners | User input in Python | Command Line Input
HTML-код
- Опубликовано: 28 сен 2024
- Check out our courses:
Spring Framework 8 Full-Day Course Live: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Enterprise Java Spring Microservices: go.telusko.com...
Coupon: TELUSKO10 (10% Discount)
Master Java Spring Development : go.telusko.com...
Coupon: TELUSKO20 (20% Discount)
Udemy Courses:
Spring: go.telusko.com...
Java:- go.telusko.com...
Java Spring:- go.telusko.com...
Java For Programmers:- go.telusko.com...
Python : go.telusko.com...
Git : go.telusko.com...
Docker : go.telusko.com...
For More Queries WhatsApp or Call on : +919008963671
website : courses.telusk...
Instagram : / navinreddyofficial
Linkedin : / navinreddy20
TELUSKO Android App : bit.ly/TeluskoApp
In this lecture we are discussing about:
- How to get user input
- input function
- printing input message
- Type of input data
- When to use index value
- eval function
- Passing values from command line
- Argument line input
#1 How to get user input
-- Getting user input in Python is straightforward. You can use the input() function
to get input from the user. The input function takes a single argument, which is the
prompt message displayed to the user.
e.g
name = input("Please enter your name: ")
x=input("Enter first number: ");
y=input("Enter second number: ");
z=x+y;
print(z);
#2 input function
-- In Python, the input() function is used to accept user input from the command line or console.
name=input("Enter your name:");
print(name);
-- In this example, the input() function prompts the user to enter their name. Whatever the user types
in response is stored in the name variable.
-- Note that the input() function always returns a string, so if we want to use the user's input as a number,
we'll need to convert it using the appropriate type-casting function (e.g., int() for integers or float() for
floating-point numbers).
#3 Types of input data
-- The input() function always returns a string, regardless of what the user enters.
we may need to convert the input to a different data type if you want to perform calculations or other operations on it.
e.g
x=input("Enter first number: ");
a=int(x);
the input entered by the user is converted to an integer using the int() function in this example.
#4 when to use index value
-- If you want to get a single character from the user, we can use the input() function and index the result.
e.g
ch=input('enter a character: ');
print(ch[0])
ch=input('enter a character: ')[0];
print(ch);
#5 eval function
eval function
-- The eval() function in Python is used to evaluate an expression entered by the user as a string.
The eval() function returns the result of the expression as a value.
e.g
x=eval(input("Enter an expression: "));
typeOf = type(x);
print(typeOf);
#6
Passing values from command line
-- sys module provides access to any command-line arguments via the sys.argv list.
we can pass arguments to a Python script from the command line using the sys.argv list.
The first argument in the list is always the name of the script itself.
suppose we have a file named Mycode.py
in file we have written code
import sys # without this line you will get error
x=sys.argv[1];
y=sys.argv[2];
z=x+y;
print(z);
in command line we have to run this file
#python3 Mycode.py 9 5
0 1 2
Note: Mycode is count as 0th argument
9 is count as 1st argument
5 is count as 2nd argument
Github :- github.com/nav...
Python for Beginners :- bit.ly/3JOLQhl
Editing Monitors :
amzn.to/2RfKWgL
amzn.to/2Q665JW
amzn.to/2OUP21a.
Java:- bit.ly/JavaUde...
Spring:- bit.ly/SpringU...
More Learning :
Java :- bit.ly/3x6rr0N
Python :- bit.ly/3GRc7JX
Django :- bit.ly/3MmoJK6
JavaScript :- bit.ly/3tiAlHo
Node JS :- bit.ly/3GT4liq
Rest Api :-bit.ly/3MjhZwt
Servlet :- bit.ly/3Q7eA7k
Spring Framework :- bit.ly/3xi7buh
Design Patterns in Java :- bit.ly/3MocXiq
Docker :- bit.ly/3xjWzLA
Blockchain Tutorial :- bit.ly/3NSbOkc
Corda Tutorial:- bit.ly/3thbUKa
Hyperledger Fabric :- bit.ly/38RZCRB
NoSQL Tutorial :- bit.ly/3aJpRuc
Mysql Tutorial :- bit.ly/3thpr4L
Data Structures using Java :- bit.ly/3MuJa7S
Git Tutorial :- bit.ly/3NXyCPu
Donation:
PayPal Id : navinreddy20
www.telusko.com
The way you making mistakes intentionally and correcting is the best of this videos which makes best way of learning.. learning from mistakes
yeah that;s right
He's awesome
chup .chal nikal,phli fursat
@@anshukumar3928 sahi hai bancho
It reminds me of the time front benchers would teach us on the exam day.
Best teacher❤️❤️
Ok ok I don't speak English very well, but I understood more you video than other videos Spanish🙆♂️ thank's
Gr8
@@koumudidurga3827 9ce
😂😂😂😂😂
2rue
10q
Sir, You Are The Best. I never had the intention to learn Python but because of your lectures and motivation videos, I started learning.
🤡
Homework done....you are teaching awesome better than the paid courses 😊🙏🙏
x = int(input ("no."))
z = x**3
Print (z)
@@meetsakhareliya755 video k end mein dekho red colour k box mein hota hai
Why do you have ther “no”? Thats string not int😅😅
(I think its joke)
Thank you
x= int(input('enter 1st number'))
print(x**3)
Can we write this using less line buddy?
1. For Pycharm
x = int(input("Enter a number:"))
y = x*x*x
print("The cube of the number is ",y)
2. For Command Line
import sys
x = int(sys.argv[1])
y = x*x*x
print("The cube of the number is ",y)
4 godziny wykladów nie dadzą tyle co 5 minut sluchania tego gościa, uwielbiam go
you are a great teacher bro, keep it up! look forward to learning programming under your guidance!
a=you're
b=great
print (a + b)
There is a mistake bro...
If Want to Store Any Sentence or Anything Character then It Should Be in quotes (type is String)
Like this: a = "Hello"
b="How r u"
Print(a+b)...
@@rohankiratsata1161 also, it would print HelloHow r u so you need to add space after hello
The fact that you get errors and correct them right after by showing us... thats what i call teaching and learning. 👏👏👏👏
Really, It's very interesting.... the way you carry the session is awesome.. intentionally you did mistake and rectify it, that is experience.... really its very useful
.
no = int(input("enter the number"))
print(no ** 3)
on command line- import sys
x = int(sys.argv[1])
print(x ** 3)
can we use print(math. pow(x,3) in both Pycharm as well as in the Command Line?
That last 'agrv' by importing from sys module is amazing :-)
------command line-----
import sys
x = int(sys.argv[1])
y = x ** 3
print(y)
It's showing eof error how can I overcome it please reply 😢😢😢😢😢😅😢😢😢
print("Fnding cube of a number ")
import sys
x=int(sys.argv[1])
y=x**3
print(y)
is the answer for the assignment
I am enjoying watching these series, thankyou navin sir
a=int(input("enter a number"))**3
Print(a)
from math import pow
x=int(input('Enter the Number'))
y=pow(x,3)
print(y)
Print(“you are best teacher your python love you 3000”)
NameError: 'Print' is not defined
😂
'P' should be of lower case bro..!
@@rajatrawat4284 😂
By giving input in Command prompt Sir i cant able to do it by my own 🥲......rest things i understand and done that too...thnkuu
3:55
Actually you could add int function before input function .. thats saves your time
Like
X=int(input("Enter 1st number"))
Y=int(input("Enter 2nd Number"))
Then you directly run the code and input the numbers and get the answers.
And you don't have to add Another line of A & B and all..
I hope this helps
Yeah he actually mentioned that in this video.
@@omkarjsuvarna i think he didn't watch the full video before commenting this ...
thank u so much sir..sir we want lecturers like u in our college..sir i have seen many videos regarding python but i was not able to write any code for given program..one of my friend suggested me to learn python from your channel and it really helped me a lot..the way of ur teaching is really awesome..thanks sir once again
name = input("what is your name?: ")
age = int(input("how old are you?: "))
age = age + 1
print("Hello "+name)
print("you are "+str(age)+" years old") why here give str plz explain
@@ManuKumar-rf5gb int type we cannot concatenate with str, so you need to change data type into str and concatenate with + 🙂
@@uday2159 tq 😊
yas=int(input("enter my number"))
X=yas ** 3
Print(X)
Thank you for this. I was training with the 100 days to code challenge and was stuck on a problem that I needed to solve, and this helped me to find the solution. Funny thing, I accidently hit submit before the test, and it worked.
from sys import argv
x=int(argv[1])
y=x**3
print(y)
Reddy garu mee teaching mindblowing Anthe 👏👏
x=int(input('Enter a number'))
z=pow(x,3)
print('The cube of'+" " +str(x)+" "+'is'+" "+str(z))
Yeah it is working even we are not importing math function
Thanks Anna..they way u tech is very special....
By the end of python course I have to learn 2 things one is python and second is the way u teach 😃 ..
Of course it's impossible to get second but I will try🤘😆
import math
a=int(input('enter a number'))
b=math.pow(a,3)
print(b)
It should be
a = float (input ("enter your number ")
Right?
@@roopa6975 yes u can but the input must be float
@@akhileshchanda4828 my quest is if you define it as int, then what should be the output if you enter a float value like 2.3? It won't give you a result. But if you define it as float, the input can be integer or a floating value. It gives output for both.
1:56 the way he teaches from here 🖤
Man, the way you explain... Thats how a teacher should be. Thank you so much for all the treasures you create.
I really had to pause the video and appreciate your teaching methods.
Hello sir. Since your teaching method and knowledge is outstanding, I wanted to let you know that not only I am learning via your methodology and have already subscribed to your channel but I also suggested your tutorials to my brother. Your are an angel. Best regards.🙏🙏🙏
to make a mistake and solve this problem step by step is the best teaching method for me not only for me but also for all watchings.thank u
0:07 I like this moment too much
Hello navin as for the quiz, this’s what I did and it worked
1. d = int(input(“enter the number to be squared ”))
2. f = d**3
3. print(f)
Amazing. I normally dont add comments on youtube videos. But the way you explain and teach is amazing. Thank you for all the learning you are imparting. Please keep up the good work. This channel for python is really helpful.
print("just love it")
Learning From The Mistakes Is Nice Bro
I have many doubts I'm started python course your video 🔥🔥🔥 completely understand 👍👍
x = int(input("Enter a number you want cube of"))
y = x**3
print(y)
This python video is still the best i have watched on youtube. kudos
For first problem its so easy you can use
---------
X = input("write 1st number")
Y = input("write 2st number")
print(x+y)
---------------
Its actually worked 😊😊
Ever since I started working almost three years ago, I felt my passion for programming started dying because in one's job programming is not really done the way we all want to, you generally need to copy paste your code without applying any thinking to it which makes this boring. The very passion which made opt for software development was dying until I found out Navin sir's playlist. My curiosity and passion is back. This is oxygen.
I was waiting to use an IDE but didn't know how to. but you are my night in a shinin' armor teacher and you taught me how to! thanks, sir!
Another great efforts to get python in PyCharm,watching in Aug2020 and believe for Python this IDE is HOT HOT HOT...Well done job Mr Naveen
using input: -
print(int(input("Enter no to find cube: "))**3)
using the command line:-
import sys
print((int(sys.argv[1]))**3)
List index out of range
import sys
x = int(sys.argv[1])
Traceback (most recent call last):
File "", line 1, in
x = int(sys.argv[1])
IndexError: list index out of range
Arguments command line nunchi isthunnam kabatti akkadi nunche rtun cheyali
You are also a comedian! Keeps it still interesting. You are a great teacher.
In Pycharm
import math as m
a = int(input("Enter a Number to Find its Cube
"))
print("The Cube of ",a,"is",(m.pow(a,3)))
I dont have my laptop with me now so I will add the cmd quiz after some time
Best teacher i have ever met. Thanks a lot sir.
Ur explanation way is super sir....im understanding very easily
you are so good at explaining , not irritating like others
I love your fun style of teaching, I am learning as well as enjoying.💕💕💕💕
1st method:
x=int(input("Enter a number: ")
y=x**3
print(y)
2nd method:
from math import *
x=float(input("Enter a number"))
y=pow(x,3)
print(y)
Man, what a great video. The way you are teaching the concept is too good. Explaining each and every step. Thank you for the wonderful video.
"""
x = input ('first')
(1)
y = input('second')
(2)
z = x + y
print (z)
return 12
"""
x = int(input('first'))
(1)
y = int(input('second'))
(2)
z = x + y
print (z)
# return 3
I just started the session and it like an addiction to learn. You are a champ. Sessions are so good & interactive.
Thanks a lot.
name='Navin Reddy'
FeelingNow='nosire'
print('thank you' ,name, FeelingNow[2:5])
Best channel for learning programming.😊
sticking to this channel for coding knowledge...awesome teacher
num1=input("enter number:")
num2=input("enter another number:")
result=float(num1)+float(num2)
print(result)
#used float to add even a decimal number
Navin your humor while session is good with special effect . Great way of interaction
number = int(input('Enter a number'))
cube = number**3
print(cube)
----------
i got help from google actually ,but i learned smth and that is important
4:16 you can also write
x = int(input("enter 1st number"))
to save ur time while coding
hope it helped
It worked in my case, at the very first try! I had 14... or maybe the new update.
x = input("Enter 1st number: ")
y = input("Enter 2nd number: ")
z = x + y
print(z)
This man is truly an amazing teacher.
superb sir i love the way you are teaching thank u very much
import math
x=int(input("enter cube number")
x=math.pow(x,3)
print(x)
from math import pow
x=int(input("enter the number to bo cube"))
y=int(pow(x,3))
print(y)
the best way to get in understand . its really very helpful with each and every detail -
def cube(x):
return x * x * x
n = int(input(" Enter the number : "))
cube1 = cube(n)
print("The Cube of {0} = {1}". format(n, cube1))
Super Teaching Anna...
Masthhh cheptunav Keka
Telugu Bhai♥️🧡
import math
x = int(input('enter the base'))
y = int(input('enter the power'))
z = pow(x,y)
print(z)
this is working for me
awesome presentation ,will surely contribute soon , keep doing good work
Like we want addition of all number so instead of int will take float it will add decimal values too
x = int(input("Enter a Number:"))
z = x ** 3
print(z)
print(x,"'s cube is",z)
i=int(input("Enter number:"))
a=i**3
print("Cube of number is {} ".format(a))
Why did you used. format in print
Navin, the way you teach is simply awesome!
Hey you are telugu, right? Telusko means "know" In telugu
def cube(x):
return x*x*x
n=int(input('enter a number'))
print("The cube of", n, "is", cube(n))
Just subscribed, you're a great teacher. This helped me so much on my project. Thank you!!!
Can I use jupyter notebook or spyder instead of pycharm
3:04 it is most important basic point which will be questioned in interviews..
once interviewer asked about it and without proper idea i said it is taking integer type 😂 but later i searched and finds it defaultly takes String type that's why we use a = int(input(" first num "))
You are awesome. Very helpful videos. Clear and concise. Thanks a lot!
Great
Type of teaching is awesome and great
Impressive
Cube of a number
from math import pow
x=int(input("enter a number "))
z=pow(x,3)
print(z)
Ans for question
import math
x=int(input('enter the value'))
y=math.pow(x,3)
print(y)
Sir pls tell me it is correct or not
i think its correct.....i tried this way.
a=int(input('enter the number here'))
b=int(a**3)
print(b)
I am impressed sir u have a lot of knowledge about python
using the command line (cmd) using the input (pycharm)
import sys
x=int(input('enter a number')
x=int(sys.argv[1])
import math
import math
y=math.pow(x,3) (or) y=(x**3) (no need for importing math if y=x**3)
z=math.pow(x,3)
print (int(y))
print (float(z))
You, sir are an excellent teacher! I love your energy.
I am impressed. I have watched 3 of your videos today for the first time and what I haven't been understanding about introduction to python is sinking in better. Thank you sir.
Thank you Sir.
for pycharm -
import math
x=int(input("enter a number")
result=math.pow(x,3)
print(result)
for cli
import sys
import math
x=int(sys.argv[1])
result=math.pow(x,3)
print(result)
hey man i love you navin reddy. you are fantastic guy loved your way of explanation and i link if it is not work then i closed the video.. kudos goes to you man
x=int(input("enter the number"))
y=pow(x, 3)
print(y)
assignment
import math as m
n = int(input('enter the num'))
print(m.pow(n, 3))
on command line-
import sys
x = int(sys.argv[1])
print(x ** 3)
ans:
1. using input()
import math
x = int(input("please enter a number: "))
cube = int(math.pow(x, 3))
print(cube)
2. using command line
import math, sys
x = int(sys.argv[1])
cube = int(math.pow(x, 3))
print(cube)
In Pycharm
import math
num=int(input('enter number to get the cube'))
result=num.__pow__(3)
print(result)
ha ha don't stop video sir, your teaching style is aswome .
Answer of the quiz
import math as m
x=int(input("Enter the number to find its cube: "))
# It will take input from user in command prompt
z=int(m.pow(x,3))
# calculate cube of that number
print(z)
number = float(input(" Please Enter any numeric Value : "))
cube = number * number * number
print("The Cube of a Given Number {0} = {1}".format(number, cube))
this one is good but for saving time:
import math
number=int(input("enter any number"))
cube=pow(number,3)
print(cube)
print("Enter a Number:")
x = int(input())
print("The Cube of the ",x ,"is ",x*x*x)
n=int(input("Enter a no.
"))
print(n*n*n)
OR
from math import pow
n=int(input('enter a no'))
c=pow(n,3)
print (c)
x=int(input('enter a value'))
import math
z=math.pow(x,3)
print("the cube root of the given number is:",z)
One doubt if we are good and better using idle why using command prompt??