Write a program that asks the user to enter an integer and prints #twotwo integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #IfIf no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying.
My concern is: is my way of coding is normal. I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help.
I think there are too many if
statements here.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying.
My concern is: is my way of coding is normal. I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help.
I think there are too many if
statements here.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
Write a program that asks the user to enter an integer and prints two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying.
My concern is: is my way of coding is normal. I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help.
I think there are too many if
statements here.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
- 29.5k
- 16
- 45
- 201
How can I simplify this code as a beginner. I think there are too many "if" here Searching for two integers root**pwr = integer(user's input)
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying.
My concern is: is my way of coding is normal and. I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help. Thank you
I think there are too many if
statements here.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
How can I simplify this code as a beginner. I think there are too many "if" here
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying. My concern is is my way of coding is normal and I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help. Thank you.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
Searching for two integers root**pwr = integer(user's input)
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying.
My concern is: is my way of coding is normal. I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help.
I think there are too many if
statements here.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
Is How can I simplify this code good for an absolute begineer?as a beginner. I think this is kind messy. To be more specific, please see belowthere are too many "if" here
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying. My concern is is my way of coding is normal and I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help. Thank you.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
Is this code good for an absolute begineer? I think this is kind messy. To be more specific, please see below
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying. My concern is is my way of coding is normal and I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help. Thank you.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))
How can I simplify this code as a beginner. I think there are too many "if" here
Write a program that asks the user to enter an integer and prints #two integers, root and pwr, such that 0 < pwr < 6 and root**pwr is equal to the integer entered by the user. #If no such pair of integers exists, it should print a message to that effect.
This is a question from MIT 6.0001 OpenCourseWare. I'm an absolute beginner (kind of started coding for 3 days) and this program costs me like 3 hours to complete. I made many modifications as running the code - finding mistakes - reviewing - then, modifying. My concern is is my way of coding is normal and I am not sure if my computational thinking reflected by this 3-hour period is on the right track to learning coding. Please feel free to judge the style, design and effectiveness of my codes. If you can give me some advice on learning, that would be a great help. Thank you.
x = int(input("Type in the number: "))
print("The root is " + str(x) + ", the power is 1 ") # A pair of numbers
#for any number
for pwr in range(1,5): #Examine by each power
root = 0
pwr += 1
while root**pwr < abs(x):
root += 1
if root**pwr == abs(x):
if x < 0 and pwr % 2 == 1:# test for negative number with odd power
root = -root
print("The root is " + str(root) + ", the power is " + str(pwr))
elif x < 0 and pwr % 2 == 0:# test for negative number with even power
print("no match for " + "power ", str(pwr) )
else:# for positive number
print("The root is " + str(root) + ", the power is " + str(pwr))
else:
print("no match for " + "power ", str(pwr))