-1
import sys
import time
import os

print("Hello My guy, welcome to the World of Programs!")


def clearConsole(): lambda: os.system('cls' if os.name in ('nt', 'dos') else 'clear')


def WP():
    new_old = input("Are you new to this world or u are new? ").lower()

    if new_old == "no" or new_old == "old":
        print("Welcome to this world my old friend, How are you doing?")
    elif new_old == "yes" or new_old == "new":
        print("Register: ")
        time.sleep(1.5)
        # asks user to enter their username
        userName = input("Pls enter your user name: ")
        # asks user to enter their password
        passWord = int(input("""Pls enter your password(numbers only): """))
        file = open("us_ps.txt")
        file.write("User name = " + userName + "\n" + "Password = " + passWord + "\n" + "Car color = ")
        file.close()
        clearConsole()
        if userName != "" and passWord != "":
            print("Lets check if you remember your password!)")

            un_check = input("Enter your user name here: ")
            ps_check = int(input("Enter your password here(numbers only): "))

            if un_check == userName and ps_check == passWord:
                print("Welcome to the World of Programs newbie, here you will learn about programs! :)")
            sys.exit()
WP()

Error:

file.write("User name = " + userName + "\n" + "Password = " + passWord + "\n" + "Car color = ")
TypeError: can only concatenate str (not "int") to str
SuperStormer
  • 4,997
  • 5
  • 25
  • 35

2 Answers2

0

You passWord variable has type int, so you should to convert it into str to concatenate it with other str:

file.write("User name = " + userName + "\n" + "Password = " + str(passWord) + "\n" + "Car color = ")
Stepan0806
  • 28
  • 6
  • 1
    Please don't answer duplicates; the comment by Superstormer means this has already been flagged as one. There are already good answers at the question that this will be closed and linked to. – CrazyChucky Feb 15 '22 at 21:10
  • take care Sthepan, since you have low points on the site, other guys feels with more power with you and will tell not to answer ahahah so smart... – L F Feb 15 '22 at 21:29
  • Just trying to be helpful. They're new here, which can be bewildering, and the ways this site works are often unintuitive. – CrazyChucky Feb 15 '22 at 22:10
0

You are receiving this error because the password is an integer, you need to convert the type to string before you write to a file using str(password):

file.write("User name = " + userName + "\n" + "Password = " + str(passWord) + "\n" + "Car color = ")

For reference: https://www.w3schools.com/python/ref_func_str.asp

Dharman
  • 30,962
  • 25
  • 85
  • 135