# Write a program to check if a string has at least one letter and one number - Python

Categories:
Viewed: 4 - Published at: a few seconds ago

### write a program to check if a string has at least one letter and one number

``````def checkString(str):

flag_l = False
flag_n = False

for i in str:

# if string has letter
if i.isalpha():
flag_l = True

# if string has number
if i.isdigit():
flag_n = True

return flag_l and flag_n

# driver code
print(checkString('helloworld'))
print(checkString('helloworld2020'))
``````

### write a program extract least frequency element

``````from collections import defaultdict
test_list = [1, 3, 4, 5, 1, 3, 5]

# printing original list
print("The original list : " + str(test_list))

# Extract least frequency element
res = defaultdict(int)
for ele in test_list:
res[ele] += 1
min_occ = 9999
for ele in res:
if min_occ > res[ele]:
min_occ = res[ele]
tar_ele = ele

# printing result
print("The minimum occurring element is : " + str(tar_ele))
``````

### write a program to check 2 lists and find if any element is common

``````def common_data(list1, list2):
result = False

for x in list1:

# traverse in the 2nd list
for y in list2:

# if one common
if x == y:
result = True
return result

return result

# driver code
a = [1, 2, 3, 4, 5]
b = [5, 6, 7, 8, 9]
print(common_data(a, b))

a = [1, 2, 3, 4, 5]
b = [6, 7, 8, 9]
print(common_data(a, b))
``````

### write a program to find area of a triangle

``````a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))

s = (a + b + c) / 2

area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)
``````

### write a program to swap two variables

``````x = input('Enter value of x: ')
y = input('Enter value of y: ')

temp = x
x = y
y = temp

print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
``````

### write a program to convert kilometers to miles

``````kilometers = float(input('How many kilometers?: '))
conv_fac = 0.621371
miles = kilometers * conv_fac
print('%0.3f kilometers is equal to %0.3f miles' %(kilometers,miles))
``````

### write a program to convert Celsius to Fahrenheit

``````celsius = float(input('Enter temperature in Celsius: '))
fahrenheit = (celsius * 1.8) + 32
print('%0.1f  Celsius is equal to %0.1f degree Fahrenheit'%(celsius,fahrenheit))
``````

### write a program to display the calender

``````import calendar
yy = int(input("Enter year: "))
mm = int(input("Enter month: "))

print(calendar.month(yy,mm))
``````

### write a program to check if the year is a leap year

``````year = int(input("Enter a year: "))
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
``````