Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A unexpected indent error
#1
Question 
Hello anyone in this forum;

I would like some help in my project.

Could anyone spot the error for me?

I encountered a SyntaxError about Unexpected indent.

Please help me figure this out, thank you.



.py   password_picker.py (Size: 619 bytes / Downloads: 84)
Reply
#2
Use code tags.
Line 14 you indent where it should not be indent.
import random
import string

adjectives = ['sleepy', 'slow', 'smelly', 'wet', 'fat', 'red', 'orange', 'yellow', 'green', 'blue', 'purple', 'fluffy', 'white', 'proud', 'brave']
nouns = ['apple', 'dinosaur', 'ball', 'toaster', 'goat', 'dragon', 'hammer', 'duck', 'panda']

print('Welcome to Password Picker!')
adjective = random.choice(adjectives)
noun = random.choice(nouns)
number = random.randrange(0,100)
special_char = random.choice(string.punctuation)
password = adjective + noun + str(number) + special_char
print(f'your new password is: {password}')
Output:
your new password is: fluffypanda36>
Reply
#3
Use code tags.
Line 14 you indent where it should not be indent.


Wdym by that tho? Can you enlighten on me on that? (It's my first time using python, sorry!)
Reply
#4
in Python indentation is an essential and mandatory part of the code.
In code under see that use 4 space indent(standar in Python) to make the if else block of code to work.
Just search Python indentation to see more examples.
name = 'Kent'
if name == 'Kent':
    print(f'Welcome {name}')
else:
    print('Dude! you are not Kent')
    print(f'Ok,hello {name}')

print('Have a great day!')
Reply
#5
Quote:use code tags
Instead of posting a link to your code, post the code, as text, and use code tags provided in this forum. This is discussed here:

Quote:Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button
.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getting unexpected indent errors trying to move cells up jensengt 4 1,819 Jun-28-2023, 12:05 PM
Last Post: deanhystad
  xml indent SubElements (wrapping) with multiple strings ctrldan 2 3,156 Jun-09-2023, 08:42 PM
Last Post: ctrldan
  IndentationError: unexpected indent dee 3 3,950 May-02-2022, 02:15 AM
Last Post: dee
  Avoid multiple repeat in indent Frankduc 8 4,511 Jan-18-2022, 05:46 PM
Last Post: Frankduc
  Unexpected syntax error djwilson0495 7 4,678 Aug-25-2020, 01:34 PM
Last Post: deanhystad
  Unexpected syntax error djwilson0495 5 3,501 Jul-20-2020, 04:23 PM
Last Post: buran
  Syntax error: "(" unexpected buttercup 4 3,985 Jul-20-2020, 06:25 AM
Last Post: buttercup
  IndentationError: unexpected indent jk91 1 3,085 Feb-27-2020, 08:56 PM
Last Post: buran
  Getting an "Unexpected Token" Error and don't know why... NotAHackusator 1 2,427 Nov-20-2019, 03:00 PM
Last Post: buran
  could not fix unexpected indent Bayan 1 4,162 Nov-08-2019, 01:45 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020