为什么我的代码中没有输出3倍的输出?

时间:2019-09-25 17:59:27

标签: python return-value

所以我正在练习python编码。我总是使用return语句,如果我需要返回一个数字,那么我什么也不会得到。但是现在,当我只想打印评论时,它什么也不会返回。即使我尝试使用return语句,它也不会返回任何内容。

def name_tag():
    name = input("Hello, whats your name? : ")
    print(f'Hi {name}, would you like to play a game?')
    print(y_n())

def y_n():
    yes_no = input("Y/N: ")

    if yes_no.lower() == 'y':
        print('Cool, than lets play a game')

    elif yes_no.lower() == 'n':
        print('To bad!')

    else:
        print('Please anwser with [y] or [n]')
        print(y_n())

这是输出

Hello, whats your name? : jop
Hi jop, would you like to play a game?
Y/N: k
Please anwser with [y] or [n]
Y/N: y
Cool, than lets play a game
None
None
None

3 个答案:

答案 0 :(得分:2)

 this.clear = function () {
            _this.newQuarters.forEach(function (_value, index) {
                _value.startDate = 0;
                _value.endDate = 0;
                _value.suppressAllocation = false;
                _value.quarters.forEach(function (_childValue, index) {
                    _childValue.startDate = 0;
                    _childValue.endDate = 0;
                    _childValue.suppressAllocation = false;
                });
            });
        };
    }

打印 this.newQuarters.forEach(function (_value, index) { var startDate = moment(_value.startDate); 函数的返回值。该值隐式为print(y_n()) ,因为该函数不返回任何内容。

答案 1 :(得分:1)

您正在打印nudge_x的结果,也就是library( ggrepel ) library( ggplot2) library( dplyr) library( scales ) library( reshape ) y <- data.frame( state = c( "AR" ) , ac = c( 0.43 ) , man = c( 0.26 ) , ltc = c( 0.25 ) , care = c( 0.05 ) , dsh = c( 0.01 ) ) y2 <- melt( y , id.var="state" ) threshold <- .07 y2 <- y2 %>% mutate(cs = rev(cumsum(rev(value))), ypos = value/2 + lead(cs, 1), ypos = ifelse(is.na(ypos), value/2, ypos), xpos = ifelse(value > threshold, 1, 1.3), xn = ifelse(value > threshold, 0, .5)) test <- ggplot( y2 , aes( x=1 , y=value , fill=variable )) + geom_bar( width = 1 , stat = "identity" ) + geom_text_repel( aes( label = paste( y2$variable , percent( value )), x = xpos, y = ypos ) , color="white" , size=5, nudge_x = y2$xn, segment.size = .5 ) + coord_polar( "y" , start = 0 ) + scale_fill_manual( values=c( "#003C64" , "#0077C8" , "#7FBBE3" , "#BFDDF1" , "#00BC87" ) ) + theme(axis.text = element_blank(), axis.ticks = element_blank(), panel.grid = element_blank()) test 尝试此操作:

y_n()

如果要使用None,可以对其进行更改,以便从def name_tag(): name = input("Hello, whats your name? : ") print(f'Hi {name}, would you like to play a game?') y_n() def y_n(): yes_no = input("Y/N: ") if yes_no.lower() == 'y': print('Cool, than lets play a game') elif yes_no.lower() == 'n': print('To bad!') else: print('Please anwser with [y] or [n]') y_n() 返回字符串:

print(y_n())

答案 2 :(得分:0)

您的代码输出None是因为您调用print(y_n())会打印y_n()函数的返回值None。您应该做的是在不使用print()的情况下调用函数,因为输出值已经在函数内部打印了。