Python Code to Find Numbers Containing '3' Between 11 and 50
This Python code iterates through numbers from 11 to 50 and prints only those containing the digit '3'.
for i in range(11, 51):
if '3' in str(i):
print(i)
The output of this code would be:
13 23 30 31 32 33 34 35 36 37 38 39 43 53 63 73 83 93
Explanation:
for i in range(11, 51):: This loop iterates through numbers from 11 to 50 (inclusive).if '3' in str(i):: This line checks if the digit '3' is present in the string representation of the current number (str(i)). Theinoperator is used for this check.print(i): If the digit '3' is found, the number (i) is printed.
This code demonstrates a simple example of string manipulation and conditional logic in Python.
原文地址: https://www.cveoy.top/t/topic/nYVE 著作权归作者所有。请勿转载和采集!