Sep-01-2017, 01:59 AM
Hi, all!
I'm new to the forums, and have a small problem on this short program homework assignment. Hopefully somebody can help me out. I'm working on a program to have the user enter a number to see if it's a perfect square. Now I wrote the program in Java (which is my first language) and translated it to Python (which i'm still frankly new with), and the program works 100% how it's supposed to, so here's the code for that:
Thanks!
I'm new to the forums, and have a small problem on this short program homework assignment. Hopefully somebody can help me out. I'm working on a program to have the user enter a number to see if it's a perfect square. Now I wrote the program in Java (which is my first language) and translated it to Python (which i'm still frankly new with), and the program works 100% how it's supposed to, so here's the code for that:
import math # get user input user_number = input("Enter a number to see if it's a perfect square: ") # define function and calculate def perfect_square(user_number): root = math.sqrt(int(user_number)) return int(root) ** 2 == int(user_number) # loop through conditions and output suites while not perfect_square(user_number): user_number = input("The number " + str(user_number) + " is 'not' a perfect square. Try again: ") else: print("\nThe number " + str(user_number) + " is a perfect square! Good job!")The problem is, I used a method in Java and a Function in Python for my calculation, but since it's so early in the class, we haven't reached the chapter in our textbook where we discuss functions. That being said, my teacher wants me to write this program without using a function, and I'm a little confused on how to do that... Any tips would be great. I know it's super easy, I just can't come up with the solution for some reason.
Thanks!