我正在尝试水平打印字符public void fileSearching(){
try{
// find1, find2 are buttons that open the file explorer
find1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view){
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
check = 0;
startActivityForResult(i, CODE);
}
});
find2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent();
i.setAction(Intent.ACTION_GET_CONTENT);
i.setType("file/*");
check = 1;
startActivityForResult(i, CODE);
}
});
}
catch (Exception ex){}
}
@Override
public void onActivityResult(int request, int result, Intent data){
if (request == CODE && result == RESULT_OK){
Uri u = data.getData();
String path = data.getData().getPath();
}
}
次数,到目前为止,我有这段代码:
n
但结果如下:
¿打印多少次*?五
*
*
*
*
*
如何水平打印星号?
EG:
#print n times *
times=input("¿How many times will it print * ? " )
for i in range(times):
print"* \t"
答案 0 :(得分:1)
首先,您需要将输入转换为int。
其次,通过在print语句的末尾添加逗号,它将以水平方式打印。
此外,当您使用python 2.x时,应使用raw_input
代替input
times = int(raw_input("How many times will it print * ? " ))
for i in range(times):
print "* \t",
<强>输出:强>
* * * * *
答案 1 :(得分:0)
你可以先试试这个。据我所知,print()在每次调用后系统地插入\ n(换行符),因此解决方案是调用&#34; print()&#34;只有一次。
#print n times *
times=input("¿How many times will it print * ? " )
str = ""
for i in range(times):
str += "* \t"
print(str)
答案 2 :(得分:0)
那是因为默认情况下,python&#39; #print n times *
import sys
times=input("¿How many times will it print * ? " )
for i in range(times):
sys.stdout.write("* \t")
#Flush the output to ensure the output has all been written
sys.stdout.flush()
函数在它之后添加换行符,您将要使用sys.stdout.write(),如您所见{ {3}}
EG:
!important