# Finding a number? If statement?

Page 1 of 1

## 5 Replies - 799 Views - Last Post: 24 October 2014 - 03:14 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=356547&amp;s=6b1d3d4e949e697cef646f645bcb8ba8&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 puck2020

Reputation: 2
• Posts: 24
• Joined: 30-August 14

# Finding a number? If statement?

Posted 24 October 2014 - 01:38 PM

When the code is run it should look to see if the number #7 has been input. I'm lost. I think I need an if state??? Not sure how to do it though...

```def main():

sum = 0.0
count = 0
num = []
xStr = input("Enter a number (<Enter> to quit) >> ")
while xStr != "":
x = eval(xStr)
num.append(x)
sum = sum + x
count = count + 1
xStr = input("Enter a number (<Enter> to quit) >> ")
num.sort()
print("You have entered", count, "number of numbers. These numbers are listed in ascending order:", num)

```

forgot main()

```def main():

sum = 0.0
count = 0
num = []
xStr = input("Enter a number (<Enter> to quit) >> ")
while xStr != "":
x = eval(xStr)
num.append(x)
sum = sum + x
count = count + 1
xStr = input("Enter a number (<Enter> to quit) >> ")
num.sort()
print("You have entered", count, "number of numbers. These numbers are listed in ascending order:", num)

main()

```

Is This A Good Question/Topic? 0

## Replies To: Finding a number? If statement?

### #2 andrewsw

• blow up my boots

Reputation: 6551
• Posts: 26,559
• Joined: 12-December 12

## Re: Finding a number? If statement?

Posted 24 October 2014 - 01:46 PM

Yes, an if-statement. tutorialspoint

Be aware that input() returns a string "7" rather than a number 7. int() can be used to convert to an integer.

BTW What book or tutorial are you reading?

This post has been edited by andrewsw: 24 October 2014 - 01:48 PM

### #3 puck2020

Reputation: 2
• Posts: 24
• Joined: 30-August 14

## Re: Finding a number? If statement?

Posted 24 October 2014 - 02:34 PM

Python Programming: An Introduction to Computer Science Second Edition John Zelle

### #4 andrewsw

• blow up my boots

Reputation: 6551
• Posts: 26,559
• Joined: 12-December 12

## Re: Finding a number? If statement?

Posted 24 October 2014 - 02:36 PM

Okay, so that should also have a section - probably a chapter - on the if-statement.

### #5 puck2020

Reputation: 2
• Posts: 24
• Joined: 30-August 14

## Re: Finding a number? If statement?

Posted 24 October 2014 - 03:05 PM

Done and done. Thanks for the help.

```def main():

sum = 0.0
count = 0
num = []
xStr = input("Enter a number (<Enter> to quit) >> ")
while xStr != "":
x = eval(xStr)
num.append(x)
sum = sum + x
count = count + 1
xStr = input("Enter a number (<Enter> to quit) >> ")
num.sort()
print("You have entered", count, "number of numbers. These numbers are listed in ascending order:", num)

if 7 not in num:
print("You did not enter the number 7.")
num.append(7)
num.reverse()
print(num)

main()

```

### #6 andrewsw

• blow up my boots

Reputation: 6551
• Posts: 26,559
• Joined: 12-December 12

## Re: Finding a number? If statement?

Posted 24 October 2014 - 03:14 PM

Glad you sorted, but don't use eval(); if you want to convert a string to an integer just use int().

eval is dangerous

This post has been edited by andrewsw: 24 October 2014 - 03:19 PM