小编CSP*_*FHS的帖子

在Python中将字符串插入列表(v.3.4.2)

我正在学习Python 3.4.2中的函数和类,我从这段代码片段的输出中得到了一些偏见:

print("This program will collect your demographic information and output it")
print ("")

class Demographics:   #This class contains functions to collect demographic info 

    def phoneFunc():  #This function will collect user's PN, including area code
        phoneNum = str(input("Enter your phone number, area code first "))
        phoneNumList = []
        phoneNumList[:0] = phoneNum
        #phoneNumList.insert(0, phoneNum) this is commented out b/c I tried this and it made the next two lines insert the dash incorrectly

        phoneNumList.insert(3, '-')
        phoneNumList.insert(7, '-')
        print(*phoneNumList)

x = Demographics …
Run Code Online (Sandbox Code Playgroud)

python string

5
推荐指数
1
解决办法
271
查看次数

从最少到最大排序3个数字

作为问题集的一部分,我必须按升序排序3个数字.一个简单的任务,但由于某种原因,我没有得到预期的结果.不允许使用数组.以下是我的代码; 我在这里链接了我的流程图.我无法让程序对5个数字进行排序,例如5,5和-4.当我尝试这种情况时,这是输出:

Enter three numbers.
Run Code Online (Sandbox Code Playgroud)

按顺序-0.04 5.0 5.0订购5.0 -0.04 5.0

如果我让那个工作,我不能得到23,0,39的情况进行排序.不确定我是否因为这么多案件而过度复杂化; 我觉得我的流程图涵盖了所有可能性.提前致谢!

  import java.util.Scanner; 

class Main {
  public static void main(String[] args) {

    Scanner reader = new Scanner(System.in); 
    System.out.print("Enter three numbers.");

    double x = reader.nextDouble();
    double y = reader.nextDouble(); 
    double z = reader.nextDouble();

    if (x >= y){
            if (y >= z)
                System.out.print("In order " + z + " "+ y + " " + x);

            if  (z >= x)
                System.out.print("In order " + y + " "+ x …
Run Code Online (Sandbox Code Playgroud)

java sorting

-2
推荐指数
1
解决办法
849
查看次数

标签 统计

java ×1

python ×1

sorting ×1

string ×1