this question should be really simple, but since im a noob to python I have no idea what to do here.
the code that I sent was:
print("what is your name?")
name=input()
then this error would appear when I tried to run it:
name '(namethatwasinput)' is not defined
it worked before so i have no idea what's going on, can anyone help?
try using
name = input("what's your name: ")
Related
I have made a "program" that creates a mikrotik config file, I am currently just running it straight as a python program, but I'd like to move it toward having a GUI, I am trying to use Tkinter for this but it is really confusing me, I was hoping someone here would be able to help me out, I don't want to show the full code because it's quite long, but I'll outline what it currently does.
mr= open(input("File Name: "), "w+")
DHCP_Range = input("DHCP Range: ")
PBX_IP = input("PBX IP: ")
DG = input("Default Gateway: ")
Network_IP = input("Network IP: ")
Currently that is the main thing the rest is mostly just the config being printed out and those variables get places throughout it as necessary.
What I want the GUI to do is ask me for the variables and then have an OK box down the bottom that then runs the rest of the script, if you guys are able to give me helpful resources or even build an example I'd be forever grateful as I'm really struggling with it.
Do you mean like having a tkinter messagebox?
If you want to prompt and ask the user its ok, you can add 2 types of codes ->
from tkinter import messagebox
messagebox.askokcancel('Ok Cancel', 'Are You sure?')
messagebox.askyesno('Yes|No', 'Do you want to proceed?')
Here is a resource that you can checkout:
[1]: https://pythonguides.com/python-tkinter-messagebox/
I'm a complete newbie when it comes to coding, so I'm probably making a stupid mistake here. What I'm doing is following along with a Python For Beginners textbook and writing the 'Hello World' exercise. I added the variable 'name' to the code and called the variable in the very next line. However, the
print('Hello', name) line of code I wrote would not print, even though my first line print('Hello, world') did print. Here's a screenshot of the code run on the Python console There are no error codes, so I'm guessing I just incorrectly defined the variable, but I'm not sure.
You need to hit Enter after Python prints 'Keenan' to print the last line.
When you call input(str), str is the prompt. Once python prints the prompt, it's waiting for an input and then Enter.
So logically speaking your code should be:
name = input("What's your name?:")
print('Hello', name)
Which will print:
What's your name?:
where you can type:
What's your name?: Keenan
followed by Enter
I need help with running a python file in VSCode. At the moment I can right-click the file and choose "Run Python File in Terminal" and it works for the simple things like:
v = "Hello World"
print(v)
However, I want to run a function with user input and I just can't get it to work. Can someone tell me how it's done? Example of a function:
def userInput():
v = input("What do you want to print? ")
print(v)
Alright, based on what I've read in the comments this should fix things:
# yourfile.py
def userInput():
v = input("What do you want to print? ")
print(v)
userInput()
The final line actually calls the function, as opposed to just defining it. If this still gives you trouble, let me know and we can keep working through things!
i'm just getting into programming and i've installed VScode and i've been using python 3.6. When i enter a simple code like:
print("Hello world!")
NAME = input("What's your name?")
print(NAME)
And when i run debug it appears the print Hello world! and the input "What's your name?" and i type whatever, and it doesn't print the NAME afterward.
Thank you in advance for the time taken to answer me.
please use IntegratedTerminal ratherthan internalTerminal
Maybe you can see it:
https://github.com/DonJayamanne/pythonVSCode/wiki/Capture-User-Input-via-input()-or-raw_input()
I tried to write my first python program and I already get an error message. In the textbook introduction to computer science using python i found the following code:
name = input('What is your name? ')
print('Hello', name)
print('Welcome to Python!')
I checked multiple times for errors and I'm quite sure i typed it exactly like the textbook states. I saved the program as MyFirstProgram.py and after that i ran the module (by pressing F5). If i understand correctly the program asks you to fill in a name. So i typed 'John'. But when i did, the following error occurs:
Traceback (most recent call last):
File "C:/Users/Wout/.ipython/MyFirstProgram.py", line 3, in <module>
name = input('What is your name? ')
File "<string>", line 1, in <module>
NameError: name 'John' is not defined
Why is 'John' not defined? Isn't it the purpose of the program to enter any name? Why do i have to define it? I followed the instructions to the letter...
Kind regards
input, in Python 2, evaluates the input as if it were a snippet of Python code. This is almost never what you want. Use raw_input instead.
By the way, you're writing your code as if it were Python 3, but you appear to be using a Python 2 interpreter. If you run your code with Python 3, it will work fine (input in Python 3 is the same as raw_input in Python 2).
You should use raw_input() instead of an input(), since you are on python-2.x:
name = raw_input('What is your name? ')
print('Hello', name)
print('Welcome to Python!')
prints:
What is your name? John
('Hello', 'John')
Welcome to Python!
You are following a textbook for Python 3 but using Python 2. In Python 2, must use raw_input and don't need brackets on print statements.
'John' will work with input (John won't work), however you should use raw_input() like the others said