Problem
stringlengths 4
623
| Solution
stringlengths 18
8.48k
⌀ | __index_level_0__
int64 0
3.31k
|
---|---|---|
Python Program to Check if a Given Key Exists in a Dictionary or Not | d={'A':1,'B':2,'C':3}
key=raw_input("Enter key to check:")
if key in d.keys():
print("Key is present and value of the key is:")
print(d[key])
else:
print("Key isn't present!") | 3,300 |
Print the Full Pyramid Number Pattern | row_size=int(input("Enter the row size:"))for out in range(1,row_size+1): for inn in range(row_size,out,-1): print(" ",end="") for p in range(1,out+1): print(out,end=" ") print("\r") | 3,301 |
Python Program to Check Whether a Number is Positive or Negative |
n=int(input("Enter number: "))
if(n>0):
print("Number is positive")
else:
print("Number is negative") | 3,302 |
The Fibonacci Sequence is computed based on the following formula:
f(n)=0 if n=0
f(n)=1 if n=1
f(n)=f(n-1)+f(n-2) if n>1
Please write a program using list comprehension to print the Fibonacci Sequence in comma separated form with a given n input by console.
|
def f(n):
if n == 0: return 0
elif n == 1: return 1
else: return f(n-1)+f(n-2)
n=int(raw_input())
values = [str(f(x)) for x in range(0, n+1)]
print ",".join(values)
| 3,303 |
Please raise a RuntimeError exception.
: |
raise RuntimeError('something wrong')
| 3,304 |
Program to print inverted right triangle alphabet pattern |
print("Enter the row and column size:");
row_size=input()
for out in range(ord(row_size),ord('A')-1,-1):
for i in range(ord('A'),out+1):
print(chr(i),end=" ")
print("\r") | 3,305 |
Program to find the sum of series 1+X+X^2/2...+X^N/N |
print("Enter the range of number:")
n=int(input())
print("Enter the value of x:")
x=int(input())
sum=1.0
i=1
while(i<=n):
sum+=pow(x,i)/i
i+=1
print("The sum of the series = ",sum) | 3,306 |