Help a Newbie! What’s Wrong with My Python Code?

0
2
Asked By CuriousCoder77 On

I'm a total beginner and I'm trying to get my first piece of code running, but it seems like I'm missing something. Here's the code I've written:

```
main( ) {
print("hello, worldn");
}
```

I'm using Python in PyCharm Community, and I thought I was hitting the right run button (the little bug up top). But nothing happens when I try to run it. Any ideas on what I'm doing wrong?

2 Answers

Answered By SyntaxSleuth42 On

You're on the right track, but it looks like you're using syntax from another programming language, likely C. In Python, we don't use curly braces. Your function should start with `def`. Here's how your code should look:

```python
def main():
print("hello, world")
```

You can just call `main()` after that to run it. Double-check that, and it should work!

Answered By CodeNewb201 On

Definitely check out the differences in syntax for Python. Your code snippet resembles C syntax too closely. In Python, you would define a function with `def`, and indentation is important! Just a tip: make sure you're using the correct syntax for the language.

CuriousCoder77 -

Oh, what should I use for Python then?

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.