PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 30, 2022

[FIXED] How to correctly format print using format in Python3 (with many arguments inside of print)?

 October 30, 2022     cs50, eof, python, python-3.x     No comments   

Issue

I'm trying to run a simple program in Python3, but I keep getting this error message after typing into the terminal python3 mario.py:

  File "mario.py", line 10
                                                ^
SyntaxError: unexpected EOF while parsing

I'm not sure why this is happening. Here is my code:

#from cs50 import get_int

height = int(input("Height: "))

if height < 1 or height > 8:
    height = get_int("Height: ")

for i in range(height):
    print(f"{"#" * i}  {"#" * i}\n", end="")

I believe it has something to do with the way I'm formatting my print function. I'm not sure which one of these to use: ' or " I would love if you could help!


Solution

You have to alternate between " and '. Try this: print(f'{" # " * i} {"#" * i}\n', end="")



Answered By - John Rayburn
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing