def func123(n):
str = ''
if 1<n<50:
for i in range(n):
for i in range(n):
str +='+'
str += "\n"
else:
return '请输入1~50之间的数字'
return str
print(func123(49))
import org.junit.jupiter.api.Test;
public class GenerateShape {
public void generateShape(int num){
if (num>0 && num<50){
for (int i=0; i<num; i++){
for (int n=0;n<num; n++){
System.out.print("*");
}
System.out.println("");
}
}else {
System.out.println("Please enter an integer between 1 and 50");
}
}
@Test
void runTests(){
generateShape(49);
}
}
‘’’
题目:给你一个整数,返回一个和整数一样长和一样宽的形状。整数是介于1和50之间。
‘’’
def zhengFX():
a = 0
try:
a = int(input(‘请输入0-50的整数:’))
except :
print(‘请输入正整数’)
else:
if a <= 0:
print(‘请输入大于0的数’)
elif a > 50:
print(‘请输入小于等于50的数’)
else:
for i in range(0, a):
print(a*"+")
zhengFX()