[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can anyone help me with some Python coding? I'm trying to

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 17
Thread images: 1

File: merkel.jpg (77KB, 580x870px) Image search: [Google]
merkel.jpg
77KB, 580x870px
Can anyone help me with some Python coding? I'm trying to make a program that determines if something is a prime number and tries to find the next one.

print('Welcome to Prime Number Checker!')
num=int(input('Enter a number you would like to check: '))

for i in range(2,num):
if num%i==0:
print('Number is composite.')
break
else:
print('Number is prime and the next prime number is',end=' ')
num+=2

for i in range(2,num):
while num%i==0:

num+=1
i+=1
continue
print(str(num)+'.')
>>
>>55795755
Who is that? Is she important?
>>
For some reason, after "num+=2", it returns "35" as the prime number after 31.
>>
I'm trying to divide a number by every number in a range and look for 0's in the remainder.
>>
>>55795783
This code isn't making sense... Why do you have two loops I'm the second part? Why not have one , maybe two functions with one loop each. Why are you posting a homework question?
>>
Sounds like homework to me, read the sticky faggot.
>>
>>55795755
this is homework. fags pls go
>>
>>55795883
It's not homework. It's just something I've been challenging myself to do.
>>
>>55795904
...for a grade, in your very first """""CS""""" course
>>
>>55795899
Delete this
>>
>>55795899
/g/ - the StackOverflow for homework questions.
>>
>>55795904
If this is challenging. Pick a new hobby like knitting or needle point m8
>>
>>55795899

why did you delete your post?
>>
>>55796042
probably because it's wrong anyway

>this entire thread
how can you fuck up so hard on a simple programming exercise
>>
>>55795755
What the fuck are you doing?
>>
>>55795781

That's moot, the founder of Microsoft.
>>
>>55795755

1. use "[ code ]" and "[ / code ]" (without the blanks) for proper code fomratting. I can't even see if you used tabs here, which is crucial in python.

2. You don't have to check from 2 to "num". It's enough to check from 2 to "num/2". Think about it.

3. This line is wrong:
print('Number is prime and the next prime number is',end=' ')
num+=2


You probably meant this:
print('Number is prime and the next prime number is',end=' ')
num*=2


But this is also unnecessary, see next point:


4. The next lines are full of mistakes..


4a) If you use "for i in range(2,num)" you don't need "num+=1"! You're just pushing the upper bound further and further. Look up how loops work in python!

4b) The line "while num%i==0" is exatly the opposite of what you want, you want "while num%i != 0"

4c) You have way too many loops. Think about what you want to do: You need ONE "while True" statement, that's it. Then you just raise num in each iteration and check if it's a prime number.
Thread posts: 17
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.