Generating Repeated Digits, Base Conversion, and Character Counting in Python
Problem 1: Generating a Number with B Repetitions of Digit A
Score: 15
Read two positive integers A (1 ≤ A ≤ 9) and B (1 ≤ B ≤ 10). Generate the integer consisting of B repetitions of the digit A.
Input Format:
A single line containing A and B separatde by a comma and optional spaces.
Output Format:
A single line containing the resulting integer.
Sample Input 1:
1, 5
Sample Output 1:
11111
Sample Input 2:
3 ,4
Sample Output 2:
3333
Solution:
a, b = input().split(',')
print(a.strip() * int(b.strip()))
Problem 2: Base Conversion Using Built-in Functions
Score: 15
Enput an integer and a base, then output the decimal (base-10) representation.
Input Format:
A single line containing the integer value and the base, separated by a comma.
Output Format:
A single line with the decimal result.
Sample Input:
45,8
Sample Output:
37
Solution:
value, base = input().split(',')
result = int(value.strip(), int(base.strip()))
print(result)
Problem 3: Counting Digits and Lowercase Letters in a String
Score: 10
Input a string and count the number of digit characters and lowercase alphabetic characters.
Input Format:
A single line containing an arbitrary string.
Output Format:
A line in the format: 共有?个数字,?个小写字符 where the question marks are relpaced by the respective counts.
Sample Input:
helo134ss12
Sample Output:
共有5个数字,6个小写字符
Solution:
s = input()
digit_count = 0
lower_count = 0
for ch in s:
if '0' <= ch <= '9':
digit_count += 1
elif 'a' <= ch <= 'z':
lower_count += 1
print(f'共有{digit_count}个数字,{lower_count}个小写字符')