Комментарии:
❤❤
ОтветитьSir last print ki bad ( ) me f ka ya Matlab hai
Ответитьthank you and sorry both
I will say the reason for sorry if you reply me
Aap achhe se Nahi samjha pate. Ho. Sirf bol dete ho Ki . I hope aap samjh gye . But students Nahi samjh pata h
ОтветитьAnyone please help me out
I think that for loop must be run in reverse order in order to get highest value otherwise code would just return I=1 because ultimately that's the first value which satisfies if condition
So I think code she be like this
def hcf(a, b):
smaller = min(a, b)
hcf = 1
for i in range(smaller,0,-1):
if a%i == 0 and b%i == 0:
hcf = i
break
return hcf
a=int(input("1st no.\n"))
b=int(input("2nd no.\n"))
print(hcf(a,b))
Last line
print(f"The gcd of these two number is {hcf}")
Why do u use' f ' key
def hcf(a, b):
highest_common_factor = 1
for numbers in range(2, max(a, b)):
if a % numbers == 0 and b % numbers == 0:
highest_common_factor = numbers
return highest_common_factor
Thank you sir 😎😍💝😍
ОтветитьWhat a lovely explanation
ОтветитьThank you so much bhai
ОтветитьI have made my own code to find the HCF/GCD using sets in python.
Ответитьthanks
Ответитьimport math
math.gcd(40,12)
output--4
this is right for gcd or not and why we are not using this , what is difference ?
# Here is a simpler way:
a = int(input("Enter first:"))
b = int(input("Enter second:"))
while a % b != 0:
remainder = a % b
a = b
b = remainder
print("HCF is:", b)
I can get LCM numbers from input using python
Ответитьharry bhai thanku
Ответитьthank you very helpful
Ответитьthis code will shoe error if we takes input (0,b) here b is any number :
def gcd(self, A, B):
if A > B:
smaller = B
bigger=A
else:
smaller = A
bigger=B
if smaller==0:
return bigger
for i in range(1, smaller+1):
if((A % i == 0) and (B % i == 0)):
k=i
return k
super explanation bro ,maza aagaya
ОтветитьMy program:
a = int(input("Enter n: " ))
l1 = [ ]
for i in range(1,a+1):
b = int(input("Enter the number: "))
l1.append(b)
c = int(min(l1))
# HCF
for i in range(1, c+1):
for numbers in l1:
if numbers%i == 0:
HCF = i
print("The HCF is " , HCF)
def GCD(a,b):
minNum = min(a,b)
maxNum = max(a,b)
rem = 1
while True:
rem = maxNum % minNum
if(rem == 0):
break
maxNum = minNum
minNum = rem
return minNum
a = int(input("Enter first number : "))
b = int(input("Enter second number : "))
result = GCD(a,b)
print(result)
# we can do like that ...!!
Bro I have another approach, instead of looping from 1 till min number and updating hcf every time, we can loop from the min of two numbers till 1 and if we find a factor for both, we assign it as hcf and break the loop. I guess this approach might reduce the num of iterations.
Ответить# this is program to get gcd of two numbers
# author ♠♠kartik♠♠
lst = [1, ]
def gcd(num1 , num2):
if num2 > num1:
upperbound = num1
else:
upperbound = num2
for i in range(2 , upperbound+1):
if num1%i == 0 and num2%i == 0:
lst.append(i)
else:
pass
if _name_ == '__main__':
num1 = int(input("Enter the number1\n"))
num2 = int(input("Enter the number1\n"))
gcd(num1,num2)
print(f"Commom factor of '{num1}' and '{num2}' is {lst}")
greatest_gcd = lst[-1]
print(f"The GCD of the number '{num1}' and '{num2}' is '{greatest_gcd}'")
###########################☻R##################
import math
gcd_number = math.gcd(num1 , num2)
print(f"GCD of the number is {gcd_number}")
Please also teach block based coding
ОтветитьGreat one vro!=
ОтветитьVery very useful 👍👍👍🎉🎉 Thanks
ОтветитьSir your method is good but I have better method with time complexity
num1=int(input("Enter firat number\n"))
num2=int(input("Wnter second number\n"))
if num1>num2:
mn=num2
else:
mn=num1
for i in range(1,int((mn/2)+1)):
if num1%i==0 and num2%i==0:
hcf=i
if num2%num1==0:
hcf=num1
print(f"Your HCF is {hcf}")
Thanks sir
Ответить# Find HCF Function
def HCF(n1,n2):
min = n1
while (True):
if (n1 % min == 0 and n2 % min == 0):
return min
min -= 1
# Main function
if __name__=="__main__":
n1 = int(input("Enter The First Number : "))
n2 = int(input("Enter The Second Number : "))
n1, n2 = min(n1, n2), max(n1, n2)
hcf = HCF(n1, n2)
print(f"{n1} & {n2} HCF is {hcf}")
# Abhishek Sharma
VERY INTERSTING SIR
Ответитьn1 = int(input("Enter the first number: "))
n2 = int(input("Enter the second number: "))
num_list = [n1,n2]
maximum_number = max(num_list)
# print(maximum_number)
num = 0
list_n1_from_loop = []
list_n2_from_loop = []
for i in range(maximum_number):
num = num + 1
if n1 % num == 0:
list_n1_from_loop.insert(0,num)
max_list_n1 = max(list_n1_from_loop)
if n2 % num == 0:
list_n2_from_loop.insert(0,num)
max_list_n2 = max(list_n2_from_loop)
convertset_n1 = set(list_n1_from_loop)
convertset_n2 = set(list_n2_from_loop)
intersection = convertset_n1.intersection(convertset_n2)
# print(sorted(intersection))
convert_intersection_list = list(intersection)
max_intersection = max(convert_intersection_list)
print(f"The maximum and similar dividable number of {n1} and {n2} with remainder 0 is: {max_intersection}\nTHANK YOU!!!!!!!!!")
2 se zyada numbers ka kya karoge?
ОтветитьInstead of updating the maximum value in for loop...we can simply run a loop in reverse direction from smaller number to 1.... correct?
Ответитьsir i tried it myself and i came up with a different logic . Please check if I m correct?
a = int(input("Enter the first number : "))
b = int(input("Enter the second number : "))
hcf=1
i=min(a,b)
while i>1:
if a%i==0 and b%i ==0:
hcf=i
break
i=i-1
print(f"The HCF of {a} & {b} is : {hcf} ")
I have learnt Python from your channel only!!
you're the BEST !!
Available with 3.9 and dict union ... beautiful feature, faster than previous
Ответитьguys u dont need to to take out the max number. you can just range from 1 to any of the two number and it will still work. example
for i in range(1, num1):
if num1%i==0 and num2%i==0:
hcf=i;
Bro we r nt getting it properly because we r nt able to see this lecture from outside home because of lecture is on dark display so plzz attention in next lecture
ОтветитьSir please make video series on unity game engine for game development and for game programming.....plz reply
ОтветитьSir Hardy Ramanujan number ke liye program banayi please
ОтветитьHarry bhai laptop bataiye hp 15s du2067tu plz bataiye kaisa h student or coding ke liye
ОтветитьPlz make a advance video for problem solving and making psudo code plzplzplzplzllz🙏🙏🙏🙏🙏
ОтветитьPlz like everyone
ОтветитьHarry bhai GCD ko Euclid division wale method se krke samjha do bhai.. Bahut problem aa rahi hai smjhne me
ОтветитьBhaiya by learning python how much salary job we can get .
ОтветитьHerry bhai you are super 😎😎😎
ОтветитьBhai ek baar heart de do
ОтветитьSir ji e commerces website per series banao
Ответить