Python Forum
Issue with if statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Issue with if statement
#1
hi there guys, I am new with python and need help with this issue as I can't seem to find any answer when I run the code. The code I used is :-
x= int(input("Enter a number: "))
if x == 1:
y += 1
print("y")

Additionally is this code correct below.
from math import*
x = int(input("Enter a number: "))
y = 5
if x ** sqrt(2) :
y = y + x
print(y)
I know you guys must be like ask teacher but I did he said to check the materials or online. How am I gonna learn when you can't help me with the mistake I create and also help me understand it.

Reply
#2
After posting your code correctly, you need to say what the issue is that you are having. For example, what output are you expecting versus the output you are getting. If you are getting errors, post the error code in it's entirety between the 'error' tags.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#3
You have to init y in the first sample:
y = 0
Reply
#4
hi sparz_alot sorry for not being clear and also thank you for telling me how to state my issue correctly and its ok now I finally got the code correctly. So the first code issue was syntax error basically issue with the structure of the code but now I fixed the issue also I identified what output I needed(which I didn't thought about it). I will this in my head when I ask for any help and also through looking for output I fixed my issue. Thanks you guys. U R GGGGGGSSS
Reply


Forum Jump:

User Panel Messages

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