Programming, oops concept, basic to advance coding, article related to computer Science like SQL database and about new technology related to computer Science.
Problem Statement: Given a number in base 10 convert it in base 2, 3, 4,5,.......,9 Code: n=int(input("enter a number with base 10:")) b=int (input("enter the base in which you want to convert:")) p=1 num=0 while(n>0): rem=n%b num=rem*p+num p=p*10 n=n//b print(num) Screansort of code and output:
Code: to read integer and string in same program: if we try to take a integer and after that a string in java it read integer successfully but skip the next line to read the string so we do this in following way.
Program to calculate permutation in python:- def fact(m): if(m==1 or m==0): return 1 else: return (m*fact(int(m)-1)) n=int(input("enter value of n:")) r=int(input("enter value of r:")) if(n>=r and r>=0): print("Permutation=",int(fact(n)/fact(n-r))) else: print("Invalid Input") Code Screenshot and output: output:
Comments
Post a Comment