#18 Python Tutorial for Beginners | User input in Python | Command Line Input
Вставка
- Опубліковано 27 сер 2024
- Check out our courses:
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❤️❤️
Man, the way you explain... Thats how a teacher should be. Thank you so much for all the treasures you create.
I tried a Udemy course to learn Python and so far these videos are so much easier to follow. And Navin explains the logic behind things which Udemy doesn't.
Bro From which platform are you doing online course suggest Me
@@chandraprasathr8231 google "python for everyone" it is a great beginner python course, it is free and available on a couple platforms
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 one of the best tutor i have ever seen i wish that our college tutor would be like you. I just hope the teachers will get some inspiration from you and try to teach in the same way you teach us.
Sir, You Are The Best. I never had the intention to learn Python but because of your lectures and motivation videos, I started learning.
🤡
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)
One of the best teachers i encountered in my life, extraordinary expression skills.Many people have knowledge but expressing them in such away that all sections of people understands is an excellent job. I am a university student struggling a lot to do my python assignments from last 25 days.I saw many videos and searched lot of websites but i dint get what i want and gave it up.Luckily i saw your channel today ,But just watching first 3 videos i got confidence that i can do it.
"Thank you for creating such excellent Python tutorials! I've been practicing from the beginning and have found them to be very helpful. One thing that would make them even better would be if you could provide practice exercises with answers at the end of each video. This would help me to test my knowledge and reinforce what I've learned. Thanks again for all your hard work!"
The best channel for all programming courses print("Ichata anni proramming course lu nerpinchabadunu")
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?
from sys import argv
x=int(argv[1])
y=int(argv[2])
z=x+y
print(z)
This is also working😎
Super dude
Also this works:
from sys import *
x=int(argv[1])
y=int(argv[2])
z=x+y
print(z)
THIS ALSO HAS WORKED, NO NEED TO USE ARGV, AS CONSOLE GIVES A SINGLE NUMBER
x = int(input('enter a value'))
y= x**3
print(y)
@@saisateeshkasaragadda7145 in pycharm you can even edit the code after running. in python IDE you cant edit. indly check clearly in which you have compiled.
Import sys
X = int(sys.argv(1)
Z = X**3
Print(Z)
Navin Ji I Am A Faculty Of Computer Science, Having 30 Years Experience,
Your Class Going In Classical Way.
My Aashribad Is With You.
Lol
4 godziny wykladów nie dadzą tyle co 5 minut sluchania tego gościa, uwielbiam go
The fact that you get errors and correct them right after by showing us... thats what i call teaching and learning. 👏👏👏👏
You are the best person I saw in any UA-cam video
Any....
@telusko using command line
import sys as s
a=int(s.argv[1])**3
print(a)
Hence the output!:)
Easy code 👍 ,
I wrote a long code which is :
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))
Assignment:
import math as m
x = int(input("Enter the number: "))
print (int(m.pow(x,3)))
good one
plz help i wrote the same way but getting error, i made a little change
import math as m
x = int(input("Enter the number: "))
print (int('the result is',m.pow(x,3)))
and the error is
TypeError: 'float' object cannot be interpreted as an integer
y bro plz tell me
@@ajaybhandari9215 bro if u have defined int then use integers only not floats
Floats-5.6 or anything with a decimal point
Integer are set of positive and negative numbers not fraction or decimal
@@ajaybhandari9215 remove this thing from the code 'the result is' then it works
@@ajaybhandari9215
x = int(input("Enter the number: "))
print ('the result is',int(m.pow(x,3)))
Sir you are the only channel who doesn't hides his mistakes Thanks a lot
------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 😢😢😢😢😢😅😢😢😢
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?
1st Q Answer:
num = int(input("Enter a number: "))
result = num ** 3
print(num, "Cube result is: ", result)
x = int(input("enter the cube number"))
cube = x*x*x
print(x,"cube result is",cube)
" is my logic corrct"
@@techops6716 can simplified with:
x=int(input("Enter the number to be cubed "))**3
print("The result is",x)
@@azazzelx very efficient 🔥
1st answer
X = int(input("enter the number to be cubed")) **3
If x! = int:
print(x)
That last 'agrv' by importing from sys module is amazing :-)
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
a= int(input('enter the value'))
print(a**3)
.
import sys
x = int(sys.argv[1])
print(x**3)
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
.
I have no programming background and I am glad I found your channel. Your way of explaining things is super helpful to me and highly motivating. Keep up the good work. Thank you Navin!
from math import pow,sqrt
x=int(input("enter a number to find power of it:: "))
print(pow(x,2))
y=int(input("enter a number to find sqrt of it:: "))
print(sqrt(y))
output___
enter a number to find power of it:: 5
25.0
enter a number to find sqrt of it:: 25
5.0
instead of converting the string type into integer you can directly take the input from the user in int type
x = int(input("Enter the 1st number")
y = int(input("Enter the 2nd number")
z = x + y
print(z)
or return(z)
didn't he already say that in the video
Lol
at 4:26 if this this not work i'll stop this video.... don't do that we're depending on your videos......if this tutorial is not understanding ...keep watching...
:::))))
Hi Navin, i am following your videos of python and it's is simply amazing. iam done around 18 videso so far and going to complete the python series in one or two weeks. Do you have have some such similar Java videos as well...pls do share the links if there. Thanks a lot again.
Little late to the fanfare party, but I agree! this man deserves some recognition among upcoming programmers.
I have done it using pow ..
import math
x= int(input("enter a number"))
print(math.pow(x,3))
x=int(input("Enter a number:"))
print(pow(x,3))
x=int(input("Enter Num"))
print(x**3)
*Without Function*
@@cabinetminister1220 yes
a=int(input("Enter number for cube"))
c=a*a*a
print(c)
X = int(input("Enter a number"))
from math import pow
print(pow(X,3))
Reddy garu mee teaching mindblowing Anthe 👏👏
using input:
import math
x = int(input("Enter a no. "))
cube = math.pow(x,3)
cube
this one is wrong
@@kannant3847
cube=int(input('enter number to find cube
='))
print(int(cube**3))
this works i think
The string point is very good. not many tutorials mention this
Print(“you are best teacher your python love you 3000”)
NameError: 'Print' is not defined
😂
'P' should be of lower case bro..!
@@rajatrawat4284 😂
I have just paused the video in the middle and came here to say..you are awesome,great way of teaching in simple language without complicating things..you are simply superb,mind blowing..I want you as my teacher of programming,please.
I really had to pause the video and appreciate your teaching methods.
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
from sys import argv
x=int(argv[1])
y=x**3
print(y)
ur teaching way is awesome ... even a 10 year child cam understand clearly😍
Just started my journey with programming. Thank you so much for your content, I have learned so much!
yas=int(input("enter my number"))
X=yas ** 3
Print(X)
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 ...
Best teacher i have ever met. Thanks a lot sir.
Great work sir, we are very blessed to have a teacher like you, thank u so much
import math
x = int(input("Enter To Get It Cube: "))
y = int(input("The power of: "))
cube = math.pow(x,y)
print(cube)
import sys
x = int(sys.argv[1])
print(x**3)
Why y? Cube means to the power 3
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.
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
This python video is still the best i have watched on youtube. kudos
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
s=int(input ("enter the value"))
print (math.pow(4,3))
correct the mistake: print (math.pow(s,3))
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 😊
You're making climbing a mountain feel like seating in a couch. What an amazing tutorial!
Can you teach some other recent topics like machine learning
+1
@@rohanchauhan5362 +69
@@mayurkalsekar524 lol
🤓 Quiz Answer 🤓
Take the input from the user using input () and also using command line.
Answer:
1) Using input method
number = int (input ("Enter any number :"))
Print (number)
2) Using command line
Import sys
number = int( sys.argv[1] )
print ( number )
print(number**3)
Its not working showing attribute error
4:32 and the award for best actor ,best teacher goes to Mr. Navin .
the you explain things even a kid will be able to understand its truly a beginners course , thank you so much sir
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
🤓 Quiz Answer 🤓
1) Write a code to find the cube of number
Answer:
number = int(input ("Please enter a number to find cube"))
Print (number**3).
Where can I find quiz questions that he mentioned
@@harisrashid0773 At the end of video.
To find the cube of the number taking input from the user
num=int(input("Enter the number:"))
print(num**3)
sir the homework is
in pycharm
x=int(input("enter the number - "))
z = x **3
print ("the cube of ", x ,'is ', z)
hope it is correct
you are the best teacher
print("ThankYou :) ")
0:07 I like this moment too much
1:56 the way he teaches from here 🖤
Import math
X=int(input(''enter the value:''))
Print(math.pow(X,3))
Hey Navin, thank you so much for the sessions !!!
I do have a doubt. Can't we use argv function in PyCharm IDE ?
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)
I love your fun style of teaching, I am learning as well as enjoying.💕💕💕💕
Learning From The Mistakes Is Nice Bro
print("just love it")
Best channel for learning programming.😊
sticking to this channel for coding knowledge...awesome teacher
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.🙏🙏🙏
x=int(input("enter number"))
y=int(input("enter number"))
z= x*y*y
print(z)
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
I think in this world this is the best tutorial for python😊
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.
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.
you are so good at explaining , not irritating like others
awesome :) 10:09 "data got corrupt while transferring from brain to mouth" it show the real programming mind awesome!!!
This man is truly an amazing teacher.
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🤘😆
Sir, your video is helping me a lot ...I will be watching all your videos on python and much more....thank you...
No words to say anything regarding your tutorial. Only a big salute.👍
You are also a comedian! Keeps it still interesting. You are a great teacher.
Ur explanation way is super sir....im understanding very easily
from math import pow
a= int(input('enter a number and i will give you its cube'))
b= 3
print(int(pow(a, b)))
and this was another project i made
y= int(input('enter an integer and i will give you its binary form, hexadecimal form and octal form'))
print(bin(y))
print(hex(y))
print(oct(y))
a = int(input("Enter a number: "))
b = int(input("Enter a number: "))
print(pow(a,b))
Navin your humor while session is good with special effect . Great way of interaction
x = int(input("Enter a number :"))
y = pow(x,3)
print("value of cube is :", y)
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!
Really a true guru u r sir really among the best teachers I ever known
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.
This is a great tutorial!!!! Thank you to the teacher!
My version of the Homework:
import sys
import math
if len(sys.argv) > 2:
print("Too many arguments entered on command line")
if len(sys.argv) == 2:
a = int(sys.argv[1])
print("The cube of", a, "is:", math.pow(a, 3))
else:
a = int(input("Enter a number: "))
print("The cube of", a, "is:", a**3)
Awesome
x = int(input("Enter a number you want cube of"))
y = x**3
print(y)
Bro salute to you and your team . Great work. Big thanks.
Thank you for very clear relevant and lucid explanation
Fantastic, due to the methods of your teaching I am really enjoying learning and practicing Python👌. Till before watching your videos I was feared of learning programming languages but not now. Thanks to your teaching💖