I just completed an assignment, and both scripts function the same ultimatley, but just wanted to know if there were any potential differences, or is it just a matter of style?

if num % 2 ==0 :
             new = num //2
             num = new
             print(num)
             count = count +1
         else:
             new = num *3 +1
             num = new
             print(num)
             count = count +1

or :

if num % 2 ==0 :
             new = num //2
             print(new)
             num = new
             count = count +1
         else:
             new = num *3 +1
             print(new)
             num = new
             count = count +1
]

you can see the new and num are reversed, and the print statement is below instead of above, again both function the same, but I'm learning python, and just want to make sure I'm learning properly and what seems like a matter of coding style can lead to disfunction down the road, or rather I dont want it to lead to disfunction!

There is no difference. The variable 'new' serves no purpose. The recommended style is

num = 3 * num + 1 if num % 2 else num // 2
print(num)
count += 1

The other highly recommended thing is to indent python code with 4 spaces. Your editor can be configured to insert 4 spaces when you hit the tab key. Read pep 8 for more advices about coding style http://www.python.org/dev/peps/pep-0008/ .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.