chomp

Sublime text can't understand gets.chomp

▼魔方 西西 提交于 2019-12-01 12:14:57
I wrote this simple program in ruby using Sublime Text and for some reason if I build it using Sublime text inbuilt system then I get the following error `deposit': undefined method `chomp' for nil:NilClass (NoMethodError) Its running perfectly if I run it using cmd. class BankAccount def initialize(name) @transactions = [] @balance = 0 end def deposit print "How much do you want to deposit?" amount = gets.chomp @balance += amount.to_f puts "$#{amount} is deposited" end def show_balance puts "Your balance is #{@balance}" end end bank_account = BankAccount.new("Rohit Begani") bank_account.class

Sublime text can't understand gets.chomp

半腔热情 提交于 2019-12-01 11:44:45
问题 I wrote this simple program in ruby using Sublime Text and for some reason if I build it using Sublime text inbuilt system then I get the following error `deposit': undefined method `chomp' for nil:NilClass (NoMethodError) Its running perfectly if I run it using cmd. class BankAccount def initialize(name) @transactions = [] @balance = 0 end def deposit print "How much do you want to deposit?" amount = gets.chomp @balance += amount.to_f puts "$#{amount} is deposited" end def show_balance puts

How to remove leading and trailing zeros in a string? Python

吃可爱长大的小学妹 提交于 2019-11-27 03:47:53
I have several alphanumeric strings like these listOfNum = ['000231512-n','1209123100000-n00000','alphanumeric0000', '000alphanumeric'] The desired output for removing trailing zeros would be: listOfNum = ['000231512-n','1209123100000-n','alphanumeric', '000alphanumeric'] The desired output for leading trailing zeros would be: listOfNum = ['231512-n','1209123100000-n00000','alphanumeric0000', 'alphanumeric'] The desire output for removing both leading and trailing zeros would be: listOfNum = ['231512-n','1209123100000-n00000','alphanumeric0000', 'alphanumeric'] For now i've been doing it the