Today is my 4rth day of coding. Today I gave my time for file handling. I have been so much confused. I am not clear about some concept of it yet. Today I also did some code on function, dictionary in some mathematical problem. I gave some time of mine to the Freecodecamp and Coursera too.
Below is the code of mine for today, which I wrote to find the HCF of two numbers. For this code, I used a function to do the job. At first, I asked the user to input two numbers integer type. Then I find the maximum and minimum of these two numbers. I created an empty list name of CF to store a common factor. I started looping from 1 to the minimum number. Because the possibility of HCF will be from 1 to a minimum among these two numbers. Below is my code.
def higher_common_factor():
n1 = int(input('enter the number'))
n2 = int(input('enter the number'))
m1 = min(n1,n2)
m2 = max(n1,n2)
cf = []
for n in range(1,m1+1):
if m1 % n == 0 and m2 % n ==0:
cf.append(n)
print(f"{cf}")
higher_common_factor()
#100DaysOfCode, day4
— Durga Pokharel (@mathdurga) December 27, 2020
* Learn about python
* HCF of two numbers
* Learn about python function#Python #CodeNewbie #beginner #functon pic.twitter.com/5ZkQCUxYmk
Top comments (4)
Your program returns the Common Factors of two numbers. A list actually..
0
is expected.it should return a number. Use
print(f"{max(cf)}")
Thanks for the suggestion.🙂
File handling in Python is actually quite simple.
Look at this example of reading a file in 2 lines of code:
Apart from Python, Ruby is quite easy to learn and is arguably simpler.
Really? I am learning python to understand code workflow.