Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 months ago.
Improve this question
If I run this script in CMD (or Git Bash - doesn't matter) using python name.py, output will show only hello and not the return value. Why is that? I tried to reinstall python, add PATH, uninstall Anaconda and install only python from official website. Code is working fine in jupyter notebook.
def to_jaden_case(string):
return ' '.join(word.capitalize() for word in string.split())
to_jaden_case("How can mirrors be real if our eyes aren't real")
print("hello")
You need to print the return value
def to_jaden_case(string):
return ' '.join(word.capitalize() for word in string.split())
print(to_jaden_case("How can mirrors be real if our eyes aren't real"))
print("hello")
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I've just started learning python today and downloaded Pycharm, but even the simplest of commands aren't working at all. Could anyone help me with this? Thank you so much.
First use this link to check whether your config is correct. If you are running the correct .py file and it's not printing.
Go to Run>Edit Configurations And select the Emulate Terminal in output console as in the picture below then it should give you output.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I am trying to make a script that can delete a file with Python. When I moved the file to my startup directory with my script, a lot of the code was changed, not by me. I've just assumed this was normal and continued trying to make it delete a file on startup. I later realized it wasn't working because one of the call methods kept getting an invalid syntax. Here's my code.
Python Version: 3.8.7
Error message is :
invalid syntax (<unknown>, line 7)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(os), STORE_NAME(os)
LOAD_CONST(0), LOAD_CONST(None), IMPORT_NAME(shutil), STORE_NAME(shutil)
source = 'C:\\Users\\me\\OneDrive\\Desktop\\startup.py'
destination = 'C:\\Users\\me\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup'
LOAD_NAME(shutil), LOAD_METHOD(move), LOAD_NAME(source), LOAD_NAME(destination), CALL_METHOD[2], STORE_NAME(new_path)
print(new_path)
LOAD_NAME(os), LOAD_METHOD(remove), LOAD_CONST('C:/Users/me/OneDrive/Desktop/delete.txt'), CALL_METHOD[1], POP_TOP
print('File Removed!'), return None
From the code, it's difficult to understand what you are trying to do. If you want to delete a file, you can use the os module in python. For example:
import os
os.remove("/some/file/path/to/remove.txt")
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 5 years ago.
Improve this question
I created this list
bikes = ['trek','redline','giant']
and now am executing this simple for loop
for bike in bikes:
print(bike)
why is this my output?
>>> for bike in bikes:
... print(bike)
...
I expected the console to print out each value from the list.
Please help!
To run a file you must:
Write out your code in a text editor.
Save the file with the extension ".py" eg. loopingThroughAList.py
Run the file from the command-line or if in IDLE select Run > Run modulue.
The command for Windows is
python -3 loopingThroughAList.py
You must also be in the same directory as the file to run it with the command above.
Hope this helped!
EDIT: You are facing this problem because you haven't ended your for loop. When running code from the console you need to enter twice to end loops and functions.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I started learning Python recently and came across of the following problem
I open a ASCII fine for reading, say data.txt and try to print it to the screen. I am using this code:
f = open("E:\ASCII\data.txt", "r")
for line in f:
print(repr(line))
This shows nothing on the screen, and the file gets erased of all the imformation contained, and gets 0kb of size.
I'm using Python 2.7.9 64-bit on Pycharm.
Thanks for all the help!
Not sure about the deletion, but this should print what you want
with open('E:\ASCII\data.txt', 'r') as f:
for line in f.read().splitlines():
print repr(line)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
In a simple program I was writing in python for experimenting with the language. My program refused to run and said there was a syntax error even though I checked it several times.
I'm currently a beginner at coding so I'm sort of pathetic when it comes to almost everything, including trying to find an answer because most of the jargons are also very new to me.
The error occurred after the if var == 2 and was shown with a red blank bar.
var = 2
if var == 2
print('yes')
else:
print('no')
You are missing a colon after the if statement.